diff mbox series

[net,v2] ibmvnic: Ensure that CRQ entry read are correctly ordered

Message ID 20210125232023.78649-1-ljp@linux.ibm.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] ibmvnic: Ensure that CRQ entry read are correctly ordered | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers warning 10 maintainers not CCed: drt@linux.ibm.com benh@kernel.crashing.org mpe@ellerman.id.au paulus@samba.org sukadev@linux.ibm.com jallen@linux.vnet.ibm.com linuxppc-dev@lists.ozlabs.org davem@davemloft.net tlfalcon@linux.vnet.ibm.com kuba@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 19 this patch: 19
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Lijun Pan Jan. 25, 2021, 11:20 p.m. UTC
Ensure that received Command-Response Queue (CRQ) entries are
properly read in order by the driver. dma_rmb barrier has
been added before accessing the CRQ descriptor to ensure
the entire descriptor is read before processing.

Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol")
Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
---
v2: drop dma_wmb according to Jakub's opinion

 drivers/net/ethernet/ibm/ibmvnic.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Jakub Kicinski Jan. 28, 2021, 1:01 a.m. UTC | #1
On Mon, 25 Jan 2021 17:20:23 -0600 Lijun Pan wrote:
> Ensure that received Command-Response Queue (CRQ) entries are
> properly read in order by the driver. dma_rmb barrier has
> been added before accessing the CRQ descriptor to ensure
> the entire descriptor is read before processing.
> 
> Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol")
> Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
> ---
> v2: drop dma_wmb according to Jakub's opinion
> 
>  drivers/net/ethernet/ibm/ibmvnic.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
> index 9778c83150f1..d84369bd5fc9 100644
> --- a/drivers/net/ethernet/ibm/ibmvnic.c
> +++ b/drivers/net/ethernet/ibm/ibmvnic.c
> @@ -5084,6 +5084,14 @@ static void ibmvnic_tasklet(struct tasklet_struct *t)
>  	while (!done) {
>  		/* Pull all the valid messages off the CRQ */
>  		while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
> +			/* Ensure that the entire CRQ descriptor queue->msgs
> +			 * has been loaded before reading its contents.

I still find this sentence confusing, maybe you mean to say stored
instead of loaded?

> +			 * This barrier makes sure ibmvnic_next_crq()'s
> +			 * crq->generic.first & IBMVNIC_CRQ_CMD_RSP is loaded
> +			 * before ibmvnic_handle_crq()'s
> +			 * switch(gen_crq->first) and switch(gen_crq->cmd).

Yup, that makes perfect sense. It's about ordering of the loads. 

> +			 */
> +			dma_rmb();
>  			ibmvnic_handle_crq(crq, adapter);
>  			crq->generic.first = 0;
>  		}
Lijun Pan Jan. 28, 2021, 1:22 a.m. UTC | #2
On Wed, Jan 27, 2021 at 7:06 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 25 Jan 2021 17:20:23 -0600 Lijun Pan wrote:
> > Ensure that received Command-Response Queue (CRQ) entries are
> > properly read in order by the driver. dma_rmb barrier has
> > been added before accessing the CRQ descriptor to ensure
> > the entire descriptor is read before processing.
> >
> > Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol")
> > Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
> > ---
> > v2: drop dma_wmb according to Jakub's opinion
> >
> >  drivers/net/ethernet/ibm/ibmvnic.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
> > index 9778c83150f1..d84369bd5fc9 100644
> > --- a/drivers/net/ethernet/ibm/ibmvnic.c
> > +++ b/drivers/net/ethernet/ibm/ibmvnic.c
> > @@ -5084,6 +5084,14 @@ static void ibmvnic_tasklet(struct tasklet_struct *t)
> >       while (!done) {
> >               /* Pull all the valid messages off the CRQ */
> >               while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
> > +                     /* Ensure that the entire CRQ descriptor queue->msgs
> > +                      * has been loaded before reading its contents.
>
> I still find this sentence confusing, maybe you mean to say stored
> instead of loaded?

The above 2 lines are the general description. The below 4 lines are
detailed explanations. If it is still confusing, we can delete the above
2 lines of comments.

>
> > +                      * This barrier makes sure ibmvnic_next_crq()'s
> > +                      * crq->generic.first & IBMVNIC_CRQ_CMD_RSP is loaded
> > +                      * before ibmvnic_handle_crq()'s
> > +                      * switch(gen_crq->first) and switch(gen_crq->cmd).
>
> Yup, that makes perfect sense. It's about ordering of the loads.
>
> > +                      */
> > +                     dma_rmb();
> >                       ibmvnic_handle_crq(crq, adapter);
> >                       crq->generic.first = 0;
> >               }
>
Jakub Kicinski Jan. 28, 2021, 1:31 a.m. UTC | #3
On Wed, 27 Jan 2021 19:22:25 -0600 Lijun Pan wrote:
> On Wed, Jan 27, 2021 at 7:06 PM Jakub Kicinski <kuba@kernel.org> wrote:
> >
> > On Mon, 25 Jan 2021 17:20:23 -0600 Lijun Pan wrote:  
> > > Ensure that received Command-Response Queue (CRQ) entries are
> > > properly read in order by the driver. dma_rmb barrier has
> > > been added before accessing the CRQ descriptor to ensure
> > > the entire descriptor is read before processing.
> > >
> > > Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol")
> > > Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
> > > ---
> > > v2: drop dma_wmb according to Jakub's opinion
> > >
> > >  drivers/net/ethernet/ibm/ibmvnic.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > >
> > > diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
> > > index 9778c83150f1..d84369bd5fc9 100644
> > > --- a/drivers/net/ethernet/ibm/ibmvnic.c
> > > +++ b/drivers/net/ethernet/ibm/ibmvnic.c
> > > @@ -5084,6 +5084,14 @@ static void ibmvnic_tasklet(struct tasklet_struct *t)
> > >       while (!done) {
> > >               /* Pull all the valid messages off the CRQ */
> > >               while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
> > > +                     /* Ensure that the entire CRQ descriptor queue->msgs
> > > +                      * has been loaded before reading its contents.  
> >
> > I still find this sentence confusing, maybe you mean to say stored
> > instead of loaded?  
> 
> The above 2 lines are the general description. The below 4 lines are
> detailed explanations. If it is still confusing, we can delete the above
> 2 lines of comments.

Yes, I'd find the comment clearer without them, thanks.
Lijun Pan Jan. 28, 2021, 1:39 a.m. UTC | #4
On Wed, Jan 27, 2021 at 7:31 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 27 Jan 2021 19:22:25 -0600 Lijun Pan wrote:
> > On Wed, Jan 27, 2021 at 7:06 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > >
> > > On Mon, 25 Jan 2021 17:20:23 -0600 Lijun Pan wrote:
> > > > Ensure that received Command-Response Queue (CRQ) entries are
> > > > properly read in order by the driver. dma_rmb barrier has
> > > > been added before accessing the CRQ descriptor to ensure
> > > > the entire descriptor is read before processing.
> > > >
> > > > Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol")
> > > > Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
> > > > ---
> > > > v2: drop dma_wmb according to Jakub's opinion
> > > >
> > > >  drivers/net/ethernet/ibm/ibmvnic.c | 8 ++++++++
> > > >  1 file changed, 8 insertions(+)
> > > >
> > > > diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
> > > > index 9778c83150f1..d84369bd5fc9 100644
> > > > --- a/drivers/net/ethernet/ibm/ibmvnic.c
> > > > +++ b/drivers/net/ethernet/ibm/ibmvnic.c
> > > > @@ -5084,6 +5084,14 @@ static void ibmvnic_tasklet(struct tasklet_struct *t)
> > > >       while (!done) {
> > > >               /* Pull all the valid messages off the CRQ */
> > > >               while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
> > > > +                     /* Ensure that the entire CRQ descriptor queue->msgs
> > > > +                      * has been loaded before reading its contents.
> > >
> > > I still find this sentence confusing, maybe you mean to say stored
> > > instead of loaded?
> >
> > The above 2 lines are the general description. The below 4 lines are
> > detailed explanations. If it is still confusing, we can delete the above
> > 2 lines of comments.
>
> Yes, I'd find the comment clearer without them, thanks.

v3 has been sent out:
https://patchwork.kernel.org/project/netdevbpf/patch/20210128013442.88319-1-ljp@linux.ibm.com/

Thanks,
Lijun
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 9778c83150f1..d84369bd5fc9 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -5084,6 +5084,14 @@  static void ibmvnic_tasklet(struct tasklet_struct *t)
 	while (!done) {
 		/* Pull all the valid messages off the CRQ */
 		while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
+			/* Ensure that the entire CRQ descriptor queue->msgs
+			 * has been loaded before reading its contents.
+			 * This barrier makes sure ibmvnic_next_crq()'s
+			 * crq->generic.first & IBMVNIC_CRQ_CMD_RSP is loaded
+			 * before ibmvnic_handle_crq()'s
+			 * switch(gen_crq->first) and switch(gen_crq->cmd).
+			 */
+			dma_rmb();
 			ibmvnic_handle_crq(crq, adapter);
 			crq->generic.first = 0;
 		}