From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757234AbcBIQyG (ORCPT ); Tue, 9 Feb 2016 11:54:06 -0500 Received: from mail-db3on0080.outbound.protection.outlook.com ([157.55.234.80]:50256 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752034AbcBIQyE convert rfc822-to-8bit (ORCPT ); Tue, 9 Feb 2016 11:54:04 -0500 X-Greylist: delayed 3424 seconds by postgrey-1.27 at vger.kernel.org; Tue, 09 Feb 2016 11:54:03 EST From: Stuart Yoder To: Mark Rutland CC: Marc Zyngier , Robin Murphy , "robh+dt@kernel.org" , "frowand.list@gmail.com" , "grant.likely@linaro.org" , "devicetree@vger.kernel.org" , "david.daney@cavium.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: RE: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base Thread-Topic: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base Thread-Index: AQHRYym4gYQx2LUpjkexROqs0kHdDZ8jni4AgAA8jYCAAAcXAIAADAqg Date: Tue, 9 Feb 2016 16:53:58 +0000 Message-ID: References: <9f6845195d03b0e0b0d187bb510fbf7bd497e836.1455015344.git.robin.murphy@arm.com> <56B9D62E.8080003@arm.com> <20160209160812.GC9332@leverpostej> In-Reply-To: <20160209160812.GC9332@leverpostej> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=nxp.com; x-originating-ip: [192.88.168.50] x-microsoft-exchange-diagnostics: 1;HE1PR04MB1643;5:U9KIDKnIr7w3lepGOiicwlnC9dcQtT+OitKHcO4ZwcQxOWGZrN3h/ZGUCIdKnCP2h1R5n6gL5PUWqBtxsEBH7vx3GTF3MgQe1mB3DWNmLHlsjVsqvAhdf3R88Jf20YjPnVnhIlb3IozcEnJMgHvn1A==;24:5GjkqFY0Pz/UgLVCGC2HNWg3IX4J4eb7YxEbTNTjhA+uiSGWi816bolXcARceSWg80wpUcaKZk51hdqFL1UnPPoca466pf5mM84Vnb8FB3Q= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR04MB1643; x-ms-office365-filtering-correlation-id: b2c1830e-96a9-4a51-81cf-08d331719b6c x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(185117386973197)(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001);SRVR:HE1PR04MB1643;BCL:0;PCL:0;RULEID:;SRVR:HE1PR04MB1643; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(24454002)(377454003)(479174004)(164054003)(51444003)(3660700001)(106116001)(11100500001)(92566002)(1220700001)(1096002)(5003600100002)(74316001)(586003)(2950100001)(2900100001)(15975445007)(77096005)(76576001)(19580405001)(102836003)(5002640100001)(6116002)(3846002)(122556002)(19580395003)(10400500002)(5008740100001)(87936001)(2906002)(93886004)(33656002)(3280700002)(76176999)(5004730100002)(86362001)(189998001)(50986999)(54356999)(4326007)(5001960100002)(110136002)(66066001);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR04MB1643;H:HE1PR04MB1641.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2016 16:53:59.0358 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB1643 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Mark Rutland [mailto:mark.rutland@arm.com] > Sent: Tuesday, February 09, 2016 10:08 AM > To: Stuart Yoder > Cc: Marc Zyngier ; Robin Murphy ; > robh+dt@kernel.org; frowand.list@gmail.com; grant.likely@linaro.org; > devicetree@vger.kernel.org; david.daney@cavium.com; linux-arm- > kernel@lists.infradead.org; linux-kernel@vger.kernel.org; stable@vger.kernel.org > Subject: Re: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base > > On Tue, Feb 09, 2016 at 03:56:55PM +0000, Stuart Yoder wrote: > > > > > -----Original Message----- > > > From: Marc Zyngier [mailto:marc.zyngier@arm.com] > > > Sent: Tuesday, February 09, 2016 6:06 AM > > > To: Robin Murphy ; robh+dt@kernel.org; frowand.list@gmail.com; > > > grant.likely@linaro.org; devicetree@vger.kernel.org > > > Cc: mark.rutland@arm.com; david.daney@cavium.com; Stuart Yoder > ; > > > linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; > > > stable@vger.kernel.org > > > Subject: Re: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base > > > > > > Hi Robin, > > > > > > On 09/02/16 11:04, Robin Murphy wrote: > > > > The existing msi-map code is fine for shifting the entire RID space > > > > upwards, but attempting finer-grained remapping reveals a bug. It turns > > > > out that we are mistakenly treating the msi-base part as an offset, not > > > > as a new base to remap onto, so things get squiffy when rid-base is > > > > nonzero. Fix this, and at the same time add a sanity check against > > > > having msi-map-mask clash with a nonzero rid-base, as that's another > > > > thing one can easily get wrong. > > > > > > > > CC: > > > > Signed-off-by: Robin Murphy > > > > > > Looks like Stuart and you both found the same bug at the same time: > > > https://lkml.org/lkml/2016/2/8/1066 > > > > > > but yours seem more correct to me (the rid_base masking in Stuart's > > > version seems odd). > > > > > > > --- > > > > drivers/of/irq.c | 9 ++++++++- > > > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/of/irq.c b/drivers/of/irq.c > > > > index 7ee21ae..e7bfc17 100644 > > > > --- a/drivers/of/irq.c > > > > +++ b/drivers/of/irq.c > > > > @@ -635,6 +635,13 @@ static u32 __of_msi_map_rid(struct device *dev, struct > > > device_node **np, > > > > msi_base = be32_to_cpup(msi_map + 2); > > > > rid_len = be32_to_cpup(msi_map + 3); > > > > > > > > + if (rid_base & ~map_mask) { > > > > + dev_err(parent_dev, > > > > + "Invalid msi-map translation - msi-map-mask (0x%x) ignores > rid- > > > base (0x%x)\n", > > > > + map_mask, rid_base); > > > > + return rid_out; > > > > + } > > > > + > > > > msi_controller_node = of_find_node_by_phandle(phandle); > > > > > > > > matched = (masked_rid >= rid_base && > > > > @@ -654,7 +661,7 @@ static u32 __of_msi_map_rid(struct device *dev, struct > device_node > > > **np, > > > > if (!matched) > > > > return rid_out; > > > > > > > > - rid_out = masked_rid + msi_base; > > > > + rid_out = masked_rid - rid_base + msi_base; > > > > dev_dbg(dev, > > > > "msi-map at: %s, using mask %08x, rid-base: %08x, msi-base: %08x, > length: > > > %08x, rid: %08x -> %08x\n", > > > > dev_name(parent_dev), map_mask, rid_base, msi_base, > > > > > > > > This computation: masked_rid - rid_base > > > > ...doesn't seem right to me. We are taking a rid that > > has been already masked and subtracting a rid base that has > > not been masked. > > The binding only mentions that the input RID is masked, not the base, so > that seems correct to me. > > > I don't see how you can combine masked and unmasked values in the same > > calculation. > > > > Say I have this msi mapping: > > > > msi-map = <0x0100 &its 0x11 0x1>; > > msi-map-mask = <0xff>; > > > > I'd say that this is an inconsistent set of properties, and it's > probably worth warning if we encounter this. There is no possible way > that rid-base can be encountered. > > > masked_rid = 0x0 > > rid_base = 0x0100 > > msi_base = 0x11 > > > > masked_rid - rid_base is 0x0 - 0x0100...which does not > > give the msi index/offset we want. > > > > Correct final answer should be 0x11. > > You can unambiguously describe this with: > > msi-map = <0x00 &its 0x11 0x1>; > msi-map-mask = <0xff>; > > This is exactly the pattern we follow in example 2 in the binding > document. > > > In my patch I masked the rid_base so it can be subtracted > > from the masked_rid. > > > > masked_rid_base = 0x00 > > > > msi_base + (masked_rid - masked_rid_base) = 0x11 > > As above, I think that this is an inconsistent DT, and we should > warn/fail in that case. Thanks...understand now. I'll test Robin's patch and confirm that it works as is for me. Thanks, Stuart From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stuart Yoder Subject: RE: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base Date: Tue, 9 Feb 2016 16:53:58 +0000 Message-ID: References: <9f6845195d03b0e0b0d187bb510fbf7bd497e836.1455015344.git.robin.murphy@arm.com> <56B9D62E.8080003@arm.com> <20160209160812.GC9332@leverpostej> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT Return-path: In-Reply-To: <20160209160812.GC9332@leverpostej> Content-Language: en-US Sender: stable-owner@vger.kernel.org To: Mark Rutland Cc: Marc Zyngier , Robin Murphy , "robh+dt@kernel.org" , "frowand.list@gmail.com" , "grant.likely@linaro.org" , "devicetree@vger.kernel.org" , "david.daney@cavium.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" List-Id: devicetree@vger.kernel.org > -----Original Message----- > From: Mark Rutland [mailto:mark.rutland@arm.com] > Sent: Tuesday, February 09, 2016 10:08 AM > To: Stuart Yoder > Cc: Marc Zyngier ; Robin Murphy ; > robh+dt@kernel.org; frowand.list@gmail.com; grant.likely@linaro.org; > devicetree@vger.kernel.org; david.daney@cavium.com; linux-arm- > kernel@lists.infradead.org; linux-kernel@vger.kernel.org; stable@vger.kernel.org > Subject: Re: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base > > On Tue, Feb 09, 2016 at 03:56:55PM +0000, Stuart Yoder wrote: > > > > > -----Original Message----- > > > From: Marc Zyngier [mailto:marc.zyngier@arm.com] > > > Sent: Tuesday, February 09, 2016 6:06 AM > > > To: Robin Murphy ; robh+dt@kernel.org; frowand.list@gmail.com; > > > grant.likely@linaro.org; devicetree@vger.kernel.org > > > Cc: mark.rutland@arm.com; david.daney@cavium.com; Stuart Yoder > ; > > > linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; > > > stable@vger.kernel.org > > > Subject: Re: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base > > > > > > Hi Robin, > > > > > > On 09/02/16 11:04, Robin Murphy wrote: > > > > The existing msi-map code is fine for shifting the entire RID space > > > > upwards, but attempting finer-grained remapping reveals a bug. It turns > > > > out that we are mistakenly treating the msi-base part as an offset, not > > > > as a new base to remap onto, so things get squiffy when rid-base is > > > > nonzero. Fix this, and at the same time add a sanity check against > > > > having msi-map-mask clash with a nonzero rid-base, as that's another > > > > thing one can easily get wrong. > > > > > > > > CC: > > > > Signed-off-by: Robin Murphy > > > > > > Looks like Stuart and you both found the same bug at the same time: > > > https://lkml.org/lkml/2016/2/8/1066 > > > > > > but yours seem more correct to me (the rid_base masking in Stuart's > > > version seems odd). > > > > > > > --- > > > > drivers/of/irq.c | 9 ++++++++- > > > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/of/irq.c b/drivers/of/irq.c > > > > index 7ee21ae..e7bfc17 100644 > > > > --- a/drivers/of/irq.c > > > > +++ b/drivers/of/irq.c > > > > @@ -635,6 +635,13 @@ static u32 __of_msi_map_rid(struct device *dev, struct > > > device_node **np, > > > > msi_base = be32_to_cpup(msi_map + 2); > > > > rid_len = be32_to_cpup(msi_map + 3); > > > > > > > > + if (rid_base & ~map_mask) { > > > > + dev_err(parent_dev, > > > > + "Invalid msi-map translation - msi-map-mask (0x%x) ignores > rid- > > > base (0x%x)\n", > > > > + map_mask, rid_base); > > > > + return rid_out; > > > > + } > > > > + > > > > msi_controller_node = of_find_node_by_phandle(phandle); > > > > > > > > matched = (masked_rid >= rid_base && > > > > @@ -654,7 +661,7 @@ static u32 __of_msi_map_rid(struct device *dev, struct > device_node > > > **np, > > > > if (!matched) > > > > return rid_out; > > > > > > > > - rid_out = masked_rid + msi_base; > > > > + rid_out = masked_rid - rid_base + msi_base; > > > > dev_dbg(dev, > > > > "msi-map at: %s, using mask %08x, rid-base: %08x, msi-base: %08x, > length: > > > %08x, rid: %08x -> %08x\n", > > > > dev_name(parent_dev), map_mask, rid_base, msi_base, > > > > > > > > This computation: masked_rid - rid_base > > > > ...doesn't seem right to me. We are taking a rid that > > has been already masked and subtracting a rid base that has > > not been masked. > > The binding only mentions that the input RID is masked, not the base, so > that seems correct to me. > > > I don't see how you can combine masked and unmasked values in the same > > calculation. > > > > Say I have this msi mapping: > > > > msi-map = <0x0100 &its 0x11 0x1>; > > msi-map-mask = <0xff>; > > > > I'd say that this is an inconsistent set of properties, and it's > probably worth warning if we encounter this. There is no possible way > that rid-base can be encountered. > > > masked_rid = 0x0 > > rid_base = 0x0100 > > msi_base = 0x11 > > > > masked_rid - rid_base is 0x0 - 0x0100...which does not > > give the msi index/offset we want. > > > > Correct final answer should be 0x11. > > You can unambiguously describe this with: > > msi-map = <0x00 &its 0x11 0x1>; > msi-map-mask = <0xff>; > > This is exactly the pattern we follow in example 2 in the binding > document. > > > In my patch I masked the rid_base so it can be subtracted > > from the masked_rid. > > > > masked_rid_base = 0x00 > > > > msi_base + (masked_rid - masked_rid_base) = 0x11 > > As above, I think that this is an inconsistent DT, and we should > warn/fail in that case. Thanks...understand now. I'll test Robin's patch and confirm that it works as is for me. Thanks, Stuart From mboxrd@z Thu Jan 1 00:00:00 1970 From: stuart.yoder@nxp.com (Stuart Yoder) Date: Tue, 9 Feb 2016 16:53:58 +0000 Subject: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base In-Reply-To: <20160209160812.GC9332@leverpostej> References: <9f6845195d03b0e0b0d187bb510fbf7bd497e836.1455015344.git.robin.murphy@arm.com> <56B9D62E.8080003@arm.com> <20160209160812.GC9332@leverpostej> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org > -----Original Message----- > From: Mark Rutland [mailto:mark.rutland at arm.com] > Sent: Tuesday, February 09, 2016 10:08 AM > To: Stuart Yoder > Cc: Marc Zyngier ; Robin Murphy ; > robh+dt at kernel.org; frowand.list at gmail.com; grant.likely at linaro.org; > devicetree at vger.kernel.org; david.daney at cavium.com; linux-arm- > kernel at lists.infradead.org; linux-kernel at vger.kernel.org; stable at vger.kernel.org > Subject: Re: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base > > On Tue, Feb 09, 2016 at 03:56:55PM +0000, Stuart Yoder wrote: > > > > > -----Original Message----- > > > From: Marc Zyngier [mailto:marc.zyngier at arm.com] > > > Sent: Tuesday, February 09, 2016 6:06 AM > > > To: Robin Murphy ; robh+dt at kernel.org; frowand.list at gmail.com; > > > grant.likely at linaro.org; devicetree at vger.kernel.org > > > Cc: mark.rutland at arm.com; david.daney at cavium.com; Stuart Yoder > ; > > > linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org; > > > stable at vger.kernel.org > > > Subject: Re: [PATCH] of/irq: Fix msi-map calculation for nonzero rid-base > > > > > > Hi Robin, > > > > > > On 09/02/16 11:04, Robin Murphy wrote: > > > > The existing msi-map code is fine for shifting the entire RID space > > > > upwards, but attempting finer-grained remapping reveals a bug. It turns > > > > out that we are mistakenly treating the msi-base part as an offset, not > > > > as a new base to remap onto, so things get squiffy when rid-base is > > > > nonzero. Fix this, and at the same time add a sanity check against > > > > having msi-map-mask clash with a nonzero rid-base, as that's another > > > > thing one can easily get wrong. > > > > > > > > CC: > > > > Signed-off-by: Robin Murphy > > > > > > Looks like Stuart and you both found the same bug at the same time: > > > https://lkml.org/lkml/2016/2/8/1066 > > > > > > but yours seem more correct to me (the rid_base masking in Stuart's > > > version seems odd). > > > > > > > --- > > > > drivers/of/irq.c | 9 ++++++++- > > > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/of/irq.c b/drivers/of/irq.c > > > > index 7ee21ae..e7bfc17 100644 > > > > --- a/drivers/of/irq.c > > > > +++ b/drivers/of/irq.c > > > > @@ -635,6 +635,13 @@ static u32 __of_msi_map_rid(struct device *dev, struct > > > device_node **np, > > > > msi_base = be32_to_cpup(msi_map + 2); > > > > rid_len = be32_to_cpup(msi_map + 3); > > > > > > > > + if (rid_base & ~map_mask) { > > > > + dev_err(parent_dev, > > > > + "Invalid msi-map translation - msi-map-mask (0x%x) ignores > rid- > > > base (0x%x)\n", > > > > + map_mask, rid_base); > > > > + return rid_out; > > > > + } > > > > + > > > > msi_controller_node = of_find_node_by_phandle(phandle); > > > > > > > > matched = (masked_rid >= rid_base && > > > > @@ -654,7 +661,7 @@ static u32 __of_msi_map_rid(struct device *dev, struct > device_node > > > **np, > > > > if (!matched) > > > > return rid_out; > > > > > > > > - rid_out = masked_rid + msi_base; > > > > + rid_out = masked_rid - rid_base + msi_base; > > > > dev_dbg(dev, > > > > "msi-map at: %s, using mask %08x, rid-base: %08x, msi-base: %08x, > length: > > > %08x, rid: %08x -> %08x\n", > > > > dev_name(parent_dev), map_mask, rid_base, msi_base, > > > > > > > > This computation: masked_rid - rid_base > > > > ...doesn't seem right to me. We are taking a rid that > > has been already masked and subtracting a rid base that has > > not been masked. > > The binding only mentions that the input RID is masked, not the base, so > that seems correct to me. > > > I don't see how you can combine masked and unmasked values in the same > > calculation. > > > > Say I have this msi mapping: > > > > msi-map = <0x0100 &its 0x11 0x1>; > > msi-map-mask = <0xff>; > > > > I'd say that this is an inconsistent set of properties, and it's > probably worth warning if we encounter this. There is no possible way > that rid-base can be encountered. > > > masked_rid = 0x0 > > rid_base = 0x0100 > > msi_base = 0x11 > > > > masked_rid - rid_base is 0x0 - 0x0100...which does not > > give the msi index/offset we want. > > > > Correct final answer should be 0x11. > > You can unambiguously describe this with: > > msi-map = <0x00 &its 0x11 0x1>; > msi-map-mask = <0xff>; > > This is exactly the pattern we follow in example 2 in the binding > document. > > > In my patch I masked the rid_base so it can be subtracted > > from the masked_rid. > > > > masked_rid_base = 0x00 > > > > msi_base + (masked_rid - masked_rid_base) = 0x11 > > As above, I think that this is an inconsistent DT, and we should > warn/fail in that case. Thanks...understand now. I'll test Robin's patch and confirm that it works as is for me. Thanks, Stuart