Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1930856ybb; Fri, 29 Mar 2019 14:28:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgwnHOirOfC6SS9tQX9i+Okq9DHXrrPZNzzp3bz/HRy/laI5rhDoDRy3LBKF+HpHLNantM X-Received: by 2002:a63:4815:: with SMTP id v21mr48388561pga.412.1553894883363; Fri, 29 Mar 2019 14:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553894883; cv=none; d=google.com; s=arc-20160816; b=xss8kyApnM3GyI4JGfXPqceIuhpCWky06g33c+A8Y89CKMDNWxJBu6Rxpat+/d5NFO xGAovsuVdN0CvNm5qPOGENfwpyfvvgDXNs+ngSgthhYd0uNf7/VbgTOQEIIRcETGow0Q d8dYi7MNo3UTTkPtL8qmPZIAT1XuZoETVmTLZasKleUl50QXA/GECtqJJ0elJS3vgfY4 N6fFjDNMtnaJOGCuZBTvh1yZ5iGd3LMn64E7bDY3bfkBLnhYadFeRj6pQAgPB4vJ3ixZ BXLvDoGFMkf9CEv28R0oS4boQMaHBk6K0iYvjSBPVVF/Ll4mNrbgEyp3KUvkaxVdoC+/ y8XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=SrxeZI0xNm9dzWvmFFvMwHqAH/sUZ2XFgxd5gGb/NsA=; b=a6UMV7ky/HC9r/agv8JNaT0hOJdap94/0JzwPS/UDEUC37s6jlzSTAN58sB21ykOp+ 5l0ml94ZL7BAdC14NC0Yy5Ucgv39FWED95kywGfrFm58wuvLivpTGLquRGUaP6YbgVys nUMZ6SsTLUf0CyoOz17uDX8iJb2Q5l77VytKIsyHfiHpiuizbYb7JB9ixAa8X7QajziR Cx09em0xRfDgIKlfFGPpm4ZFe0sgA+n7j+s0EI2UMwenOrGKSKyxqo47AiczwFmvZUFA O7jqwRrbmFikgPR5nMAOa41mq/nuhsgkTtqF0Z1P/NzLpzPSlNzPzWBOhP8LEGlabZI6 NvAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LhmyzT4z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si2722048pgc.307.2019.03.29.14.27.47; Fri, 29 Mar 2019 14:28:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LhmyzT4z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730241AbfC2VZn (ORCPT + 99 others); Fri, 29 Mar 2019 17:25:43 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:45976 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729652AbfC2VZm (ORCPT ); Fri, 29 Mar 2019 17:25:42 -0400 Received: by mail-oi1-f196.google.com with SMTP id y84so2780532oia.12 for ; Fri, 29 Mar 2019 14:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=SrxeZI0xNm9dzWvmFFvMwHqAH/sUZ2XFgxd5gGb/NsA=; b=LhmyzT4zWeJlaOW591zu+6ntI6jBc/ZheRj/nkGiZ0uVMCV/K+24rq7TY9U4J+HjQA yPNiGgSpeFQyx1dU6OWJZxcTkFB2pVASLbvAFx+yVs1Nm8fIeV+tgKA1ue5PTt3zvjtr o+oY7p8+LVoeflep5UKqtSzV3whP7kXKhy/GulRL3ISURMqehv21kmS3UyuBW3XX4QZh BuB/DiDgBUksH37KDj20mbh49qQvfmhKLa2Fl7Nil96V45NYz7prHNUyyWT25DDdYQaH DOpfuwAdcX3GMClWJla8V95SW2bYu3Q5o9BkQvgvK1z1UoZo3LG0TbhEoJMhaW5nEBHA bY8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=SrxeZI0xNm9dzWvmFFvMwHqAH/sUZ2XFgxd5gGb/NsA=; b=pznJP1RuyUaokQRRNqL7rp+94AD3ZIGg6156eCg6MwCgCB77ti+1E588/GmYtVIMCi zeBiLsCxvbp+/cnKS6AVq4E4UyDp03eEHhvAFUpDcekNaBlTXKDXGsD5EwfZxWSmOnNC g3L4aChqAp3B+A+MaoZN16Ko43Qj7myAg653pA9t4Yxpz2fxC+m3DUca9Avo4m+wDmU6 YsmCaXDlemAsxVB8xz8WXhvGaTwwvcG0nTaJ3RIiS9BXHjz4g4x/5fFMPC6Uh/s8cAQc idH/FcFAZaRlJ2rS08se5X8IOB0IYggDUKxC8f+0WSIuyJLdcY5KFj1X2VtU4us/fC9w RAPA== X-Gm-Message-State: APjAAAUnpBHYwgrOvZdjVAkE+wkQ5ehOuKQW/LrLTtqAq8HERsn+8E9e yzvrdUuNnmSoWUJBE0FhXWsThS9m8AJZo5UUss7cQw== X-Received: by 2002:aca:e4cc:: with SMTP id b195mr5260368oih.39.1553894741377; Fri, 29 Mar 2019 14:25:41 -0700 (PDT) MIME-Version: 1.0 References: <20190328225925.241998-1-jannh@google.com> <530a0823-5dcd-9006-2057-ae5b9da2389a@codeaurora.org> In-Reply-To: From: Jann Horn Date: Fri, 29 Mar 2019 22:25:15 +0100 Message-ID: Subject: Re: [PATCH] x86/calgary: fix bitcast type warnings To: Mukesh Ojha , Logan Gunthorpe , =?UTF-8?Q?Horia_Geant=C4=83?= Cc: Muli Ben-Yehuda , Jon Mason , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , iommu@lists.linux-foundation.org, kernel list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 29, 2019 at 10:19 PM Jann Horn wrote: > > +Logan Gunthorpe and Horia Geant=C4=83, since they've written a bunch of = this code > > On Fri, Mar 29, 2019 at 5:48 PM Jann Horn wrote: > > On Fri, Mar 29, 2019 at 9:19 AM Mukesh Ojha wrot= e: > > > On 3/29/2019 4:29 AM, Jann Horn wrote: > > > > The sparse checker attempts to ensure that all conversions between > > > > fixed-endianness numbers and numbers with native endianness are exp= licit. > > > > However, the calgary code reads and writes big-endian numbers from/= to IO > > > > memory using {read,write}{l,q}(), which return native-endian number= s. > > > > > > > > This could be addressed by putting __force casts all over the place= , but > > > > that would kind of defeat the point of the warning. Instead, create= new > > > > helpers {read,write}{l,q}_be() for big-endian IO that convert from/= to > > > > native endianness. > > > > > > > > Most of this patch is a straightforward conversion; the following p= arts > > > > aren't just mechanical replacement: > > > > > > > > - ->tar_val is now a native-endian number instead of big-endian > > > > - calioc2_handle_quirks() did `cpu_to_be32(readl(target))` when i= t > > > > intended to do `be32_to_cpu(readl(target))` (but that has no ac= tual > > > > effects outside of type warnings) > > > > > > > > This gets rid of 108 lines of sparse warnings. > > > > > > > > Signed-off-by: Jann Horn > > > > --- > > > > compile-tested only > > > > > > > > arch/x86/kernel/pci-calgary_64.c | 108 ++++++++++++++++++--------= ----- > > > > 1 file changed, 64 insertions(+), 44 deletions(-) > > > > > > > > diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci= -calgary_64.c > > > > index c70720f61a34..36cd66d940fb 100644 > > > > --- a/arch/x86/kernel/pci-calgary_64.c > > > > +++ b/arch/x86/kernel/pci-calgary_64.c > > > > @@ -534,6 +534,26 @@ static inline int is_cal_pci_dev(unsigned shor= t device) > > > > return (is_calgary(device) || is_calioc2(device)); > > > > } > > > > > > > > > Can the existing api's not be used here like iowrite64be/ioread64be/ = or > > > similar variant in "include/asm-generic/io.h" > > > > Oooh! I didn't realize that those exist. I'll change that and send a v2= . > > Actually, that doesn't work at the moment on x86-64: > > include/asm-generic/io.h only defines these things if > CONFIG_GENERIC_IOMAP isn't defined; and X86 unconditionally defines > it. With CONFIG_GENERIC_IOMAP set, these functions are provided by > include/asm-generic/iomap.h. > > include/asm-generic/iomap.h has extern definitions of them: > > extern unsigned int ioread8(void __iomem *); > extern unsigned int ioread16(void __iomem *); > extern unsigned int ioread16be(void __iomem *); > extern unsigned int ioread32(void __iomem *); > extern unsigned int ioread32be(void __iomem *); > #ifdef CONFIG_64BIT > extern u64 ioread64(void __iomem *); > extern u64 ioread64be(void __iomem *); > #endif > [...] > extern void iowrite8(u8, void __iomem *); > extern void iowrite16(u16, void __iomem *); > extern void iowrite16be(u16, void __iomem *); > extern void iowrite32(u32, void __iomem *); > extern void iowrite32be(u32, void __iomem *); > #ifdef CONFIG_64BIT > extern void iowrite64(u64, void __iomem *); > extern void iowrite64be(u64, void __iomem *); > #endif > > The definitions for these are in lib/iomap.c, except that there are no > definitions for ioread64be() and iowrite64be(); if you try to use > them, you get linker errors. > > I guess maybe the fix for that would be to, in iomap.c, just implement > iowrite64{,be} the same way as iowrite32{,be}, just under a "#ifdef > CONFIG_64BIT"? ... nope, I don't think I can figure out the proper fix here. There is no inq(), because 64-bit port I/O apparently isn't a thing. So it'd have to use pio_read64_lo_hi() for ports, but readq() for MMIO? Which is what ioread64_lo_hi() already does? I'm confused.