diff mbox

[1/3] PCI: hv: use the correct buffer size in new_pcichild_device()

Message ID MWHPR03MB26695762E11D248A4181F43EBFB80@MWHPR03MB2669.namprd03.prod.outlook.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Dexuan Cui Nov. 10, 2016, 7:17 a.m. UTC
We don't really need such a big on-stack buffer.
vmbus_sendpacket() here only uses sizeof(struct pci_child_message).

Signed-off-by: Dexuan Cui <decui@microsoft.com>
CC: Jake Oshins <jakeo@microsoft.com>
Cc: KY Srinivasan <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 drivers/pci/host/pci-hyperv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Jake Oshins Nov. 10, 2016, 4:27 p.m. UTC | #1
> -----Original Message-----
> From: Dexuan Cui
> Sent: Wednesday, November 9, 2016 11:18 PM
> To: Bjorn Helgaas <bhelgaas@google.com>; linux-pci@vger.kernel.org;
> devel@linuxdriverproject.org
> Cc: gregkh@linuxfoundation.org; KY Srinivasan <kys@microsoft.com>;
> Haiyang Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Jake Oshins <jakeo@microsoft.com>; Hadden
> Hoppert <haddenh@microsoft.com>; Vitaly Kuznetsov
> <vkuznets@redhat.com>; jasowang@redhat.com; apw@canonical.com;
> olaf@aepfle.de; linux-kernel@vger.kernel.org
> Subject: [PATCH 1/3] PCI: hv: use the correct buffer size in
> new_pcichild_device()
> 
> We don't really need such a big on-stack buffer.
> vmbus_sendpacket() here only uses sizeof(struct pci_child_message).
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> CC: Jake Oshins <jakeo@microsoft.com>
> Cc: KY Srinivasan <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> CC: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  drivers/pci/host/pci-hyperv.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
> index 763ff87..93ed64a 100644
> --- a/drivers/pci/host/pci-hyperv.c
> +++ b/drivers/pci/host/pci-hyperv.c
> @@ -1271,9 +1271,9 @@ static struct hv_pci_dev
> *new_pcichild_device(struct hv_pcibus_device *hbus,
>  	struct hv_pci_dev *hpdev;
>  	struct pci_child_message *res_req;
>  	struct q_res_req_compl comp_pkt;
> -	union {
> -	struct pci_packet init_packet;
> -		u8 buffer[0x100];
> +	struct {
> +		struct pci_packet init_packet;
> +		u8 buffer[sizeof(struct pci_child_message)];
>  	} pkt;
>  	unsigned long flags;
>  	int ret;
> --
> 2.7.4

This change seems good to me, in that it's always a bad idea to use too much stack.  But this won't fix the problem with VMAP_STACK.  The buffer could still end up spanning two pages and the physical addresses of those pages would possibly be discontiguous.  Do you want to just refactor this so that it uses a fixed buffer, one that will work with VMAP_STACK?  Or is that coming in a future patch? 

-- Jake Oshins

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dexuan Cui Nov. 10, 2016, 4:52 p.m. UTC | #2
> From: Jake Oshins
> > From: Dexuan Cui
> > Sent: Wednesday, November 9, 2016 11:18 PM
> > We don't really need such a big on-stack buffer.
> > vmbus_sendpacket() here only uses sizeof(struct pci_child_message).
> >
> > @@ -1271,9 +1271,9 @@ static struct hv_pci_dev
> > *new_pcichild_device(struct hv_pcibus_device *hbus,
> >  	struct hv_pci_dev *hpdev;
> >  	struct pci_child_message *res_req;
> >  	struct q_res_req_compl comp_pkt;
> > -	union {
> > -	struct pci_packet init_packet;
> > -		u8 buffer[0x100];
> > +	struct {
> > +		struct pci_packet init_packet;
> > +		u8 buffer[sizeof(struct pci_child_message)];
> >  	} pkt;
> >  	unsigned long flags;
> >  	int ret;
> 
> This change seems good to me, in that it's always a bad idea to use too much
> stack.  But this won't fix the problem with VMAP_STACK.  The buffer could still
> end up spanning two pages and the physical addresses of those pages would
> possibly be discontiguous.  Do you want to just refactor this so that it uses a
> fixed buffer, one that will work with VMAP_STACK?  Or is that coming in a future
> patch?

Hi Jake, I think the VMAP_STACK issue you mentioned should be another different
issue fixed by Long Li: https://patchwork.ozlabs.org/patch/692447/. 

The VMAP_STACK issue is only an issue when we pass the buffer's physical address
to the hypercall.

Here the buffer is not passed to any hypercall. We just use vmbus_sendpacket()
to memcpy the buffer into the per-channel ringbuffer.

Thanks,
-- Dexuan
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jake Oshins Nov. 10, 2016, 5:05 p.m. UTC | #3
> -----Original Message-----
> 
> > From: Jake Oshins
> > > From: Dexuan Cui
> > > Sent: Wednesday, November 9, 2016 11:18 PM
> > > We don't really need such a big on-stack buffer.
> > > vmbus_sendpacket() here only uses sizeof(struct pci_child_message).
> > >
> > > @@ -1271,9 +1271,9 @@ static struct hv_pci_dev
> > > *new_pcichild_device(struct hv_pcibus_device *hbus,
> > >  	struct hv_pci_dev *hpdev;
> > >  	struct pci_child_message *res_req;
> > >  	struct q_res_req_compl comp_pkt;
> > > -	union {
> > > -	struct pci_packet init_packet;
> > > -		u8 buffer[0x100];
> > > +	struct {
> > > +		struct pci_packet init_packet;
> > > +		u8 buffer[sizeof(struct pci_child_message)];
> > >  	} pkt;
> > >  	unsigned long flags;
> > >  	int ret;
> >
> > This change seems good to me, in that it's always a bad idea to use too
> much
> > stack.  But this won't fix the problem with VMAP_STACK.  The buffer could
> still
> > end up spanning two pages and the physical addresses of those pages
> would
> > possibly be discontiguous.  Do you want to just refactor this so that it uses
> a
> > fixed buffer, one that will work with VMAP_STACK?  Or is that coming in a
> future
> > patch?
> 
> Hi Jake, I think the VMAP_STACK issue you mentioned should be another
> different
> issue fixed by Long Li: https://patchwork.ozlabs.org/patch/692447/.
> 
> The VMAP_STACK issue is only an issue when we pass the buffer's physical
> address
> to the hypercall.
> 
> Here the buffer is not passed to any hypercall. We just use
> vmbus_sendpacket()
> to memcpy the buffer into the per-channel ringbuffer.
> 
> Thanks,
> -- Dexuan

Yes, you're right.  This patch looks fine to me.  Sorry for confusing the two issues.

-- Jake
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
KY Srinivasan Nov. 14, 2016, 10:58 p.m. UTC | #4
> -----Original Message-----
> From: Dexuan Cui
> Sent: Wednesday, November 9, 2016 11:18 PM
> To: Bjorn Helgaas <bhelgaas@google.com>; linux-pci@vger.kernel.org;
> devel@linuxdriverproject.org
> Cc: gregkh@linuxfoundation.org; KY Srinivasan <kys@microsoft.com>;
> Haiyang Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Jake Oshins <jakeo@microsoft.com>; Hadden
> Hoppert <haddenh@microsoft.com>; Vitaly Kuznetsov
> <vkuznets@redhat.com>; jasowang@redhat.com; apw@canonical.com;
> olaf@aepfle.de; linux-kernel@vger.kernel.org
> Subject: [PATCH 1/3] PCI: hv: use the correct buffer size in
> new_pcichild_device()
> 
> We don't really need such a big on-stack buffer.
> vmbus_sendpacket() here only uses sizeof(struct pci_child_message).
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> CC: Jake Oshins <jakeo@microsoft.com>
> Cc: KY Srinivasan <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> CC: Vitaly Kuznetsov <vkuznets@redhat.com>

Thanks Dexuan.

Acked-by: K. Y. Srinivasan <kys@microsoft.com>

> ---
>  drivers/pci/host/pci-hyperv.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
> index 763ff87..93ed64a 100644
> --- a/drivers/pci/host/pci-hyperv.c
> +++ b/drivers/pci/host/pci-hyperv.c
> @@ -1271,9 +1271,9 @@ static struct hv_pci_dev
> *new_pcichild_device(struct hv_pcibus_device *hbus,
>  	struct hv_pci_dev *hpdev;
>  	struct pci_child_message *res_req;
>  	struct q_res_req_compl comp_pkt;
> -	union {
> -	struct pci_packet init_packet;
> -		u8 buffer[0x100];
> +	struct {
> +		struct pci_packet init_packet;
> +		u8 buffer[sizeof(struct pci_child_message)];
>  	} pkt;
>  	unsigned long flags;
>  	int ret;
> --
> 2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index 763ff87..93ed64a 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -1271,9 +1271,9 @@  static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,
 	struct hv_pci_dev *hpdev;
 	struct pci_child_message *res_req;
 	struct q_res_req_compl comp_pkt;
-	union {
-	struct pci_packet init_packet;
-		u8 buffer[0x100];
+	struct {
+		struct pci_packet init_packet;
+		u8 buffer[sizeof(struct pci_child_message)];
 	} pkt;
 	unsigned long flags;
 	int ret;