Received: by 10.223.176.5 with SMTP id f5csp764860wra; Wed, 7 Feb 2018 07:12:08 -0800 (PST) X-Google-Smtp-Source: AH8x227wCa+hKf1SYF9fWbADCrZYEb7LQ0glpAbCxO+r/0s6+fUzhq2M5Cod63M7FqJvf0BcMNHu X-Received: by 10.99.131.193 with SMTP id h184mr5234773pge.25.1518016328542; Wed, 07 Feb 2018 07:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518016328; cv=none; d=google.com; s=arc-20160816; b=efqSb2FWSmOBMNHlTJhzy0rGjDud+Fl/a0dFvJiebG3tNsmIteXothMmruRqXaqfHP QGrLiikPoEB7TQRdqBkwNdBSeTqSE1aLspIdZeYHCG7+RMPrmThjGKdI8iX2g74D5g99 00rkK7cransA8MMBGWFoaoaZk2HyjcAzI+GyuejFITzaksyn9YBD0QmybSq3KCLRKE65 8lY2bvYnS/lU2CBqLLDkmEAOjszGJoNmOzMFTRyinIsIXoAN47T+R9Utdvxh+pbhMzuW oOPC1cqDS0Uki5hbWVVJWgDjxyNVo8k8FN8CxK1EZ1k9carNprazouWd9Hzz9nV84oua Y9tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=lsGMMdS00V0S8rZZkJMNZ48VF86b900Ulbx6+LTOTeA=; b=BgDtM4iyVH1qtQVGbxt5tnnIyo1zW+kJ7EouzwLDUDIkEB4d6cHfDTSAlbB88ZLAYC ctCWxbRysPYGLGZfrJo7ClNMhsrEp9h6NbDRwgUD+vJ2GFnhm79XeqEUSEKVKVxCewo7 GLRpYwNEoU3n4GCPxMYNr9s2zB8lMHDBD71Qv00iouhbAVOIMZqI0cfEGm4DQ7TxsS/2 IgvLwq3JJMua6mUrR32dVctwWlvL5l5zQn1DdLgB+yEHDHTxBf59iChuwfznxe7FWewP vdMmYtAeM/CJ2N4YAGFXBKsMI5AxKLEx35kg+bIE2lzddZzKPPTk50Cu9BvStDF5F50v ue+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WozAqWY7; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8-v6si1208622plk.535.2018.02.07.07.11.54; Wed, 07 Feb 2018 07:12:08 -0800 (PST) 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=@linaro.org header.s=google header.b=WozAqWY7; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754558AbeBGPK2 (ORCPT + 99 others); Wed, 7 Feb 2018 10:10:28 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:55919 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754503AbeBGPK0 (ORCPT ); Wed, 7 Feb 2018 10:10:26 -0500 Received: by mail-wm0-f66.google.com with SMTP id 143so3731198wma.5 for ; Wed, 07 Feb 2018 07:10:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lsGMMdS00V0S8rZZkJMNZ48VF86b900Ulbx6+LTOTeA=; b=WozAqWY7onGTMRPXkEQijtIMI1GjuIbgr7pk9QX69HbxQ3q8nHdNNlbHvsCUjBaFQW UxI+tPRSCUSQuaqS1KsqpD4+SxKIDD4ggkAX1MfCNfsA8QL1orXA80jp/bL9qlIn5Nww hu4yEzMHzfQUYYBoux14yErKmp+rUgxop1nlI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lsGMMdS00V0S8rZZkJMNZ48VF86b900Ulbx6+LTOTeA=; b=e8+qFOINy3Q9PR2sHYR2m4eD+oswyK+6sGD9++QQwUOSpPIJ3R8EoERtAQxuEGbzZC 46xbfFi/gAJb4Gcctjnpm1aSRLoRPF3uDWBqVHTYyfvQZvZ9Glj6/nXl7kiG6ARwXQLe uJgqEi6TusZwQfUqo5M4wFgtNz2UnNY3MI4IPfe3RK8s7VfepgNiKcgIBzT7uBr5ALnB O6tuJ7G4xI3PYV0voSUmQQShxcbMD9cHmd2ixxVL8O78Nz3i9eZgltsG7uUWn6+ZalaH 1UK3nrVunCJXLI9gqv453hp4rHgMdwMj8JFTSvxB6mBsFgaknwOHbuRP0Cf8HmIvU1Ln 7cjQ== X-Gm-Message-State: APf1xPCH2irMw0Xks1AcMMxaem6bbdAeonOhchYhFVjllPEq6QlaJ6bS tpJJZR7uhlQPfrw7D2TweIRwxw== X-Received: by 10.80.240.205 with SMTP id a13mr8678262edm.77.1518016225575; Wed, 07 Feb 2018 07:10:25 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id l9sm1160365edi.34.2018.02.07.07.10.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2018 07:10:24 -0800 (PST) Date: Wed, 7 Feb 2018 16:10:23 +0100 From: Christoffer Dall To: Suzuki K Poulose Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, linux-kernel@vger.kernel.org, kristina.martsenko@arm.com, peter.maydell@linaro.org, pbonzini@redhat.com, rkrcmar@redhat.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, catalin.marinas@arm.com, Shanker Donthineni Subject: Re: [PATCH v1 02/16] irqchip: gicv3-its: Add helpers for handling 52bit address Message-ID: <20180207151023.GD29286@cbox> References: <20180109190414.4017-1-suzuki.poulose@arm.com> <20180109190414.4017-3-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180109190414.4017-3-suzuki.poulose@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Suzuki, On Tue, Jan 09, 2018 at 07:03:57PM +0000, Suzuki K Poulose wrote: > Add helpers for encoding/decoding 52bit address in GICv3 ITS BASER > register. When ITS uses 64K page size, the 52bits of physical address > are encoded in BASER[47:12] as follows : > > Bits[47:16] of the register => bits[47:16] of the physical address > Bits[15:12] of the register => bits[51:48] of the physical address > bits[15:0] of the physical address are 0. > > Also adds a mask for CBASER address. This will be used for adding 52bit > support for VGIC ITS. More importantly ignore the upper bits if 52bit > support is not enabled. > > Cc: Shanker Donthineni > Cc: Marc Zyngier > Signed-off-by: Suzuki K Poulose > --- > drivers/irqchip/irq-gic-v3-its.c | 2 +- > include/linux/irqchip/arm-gic-v3.h | 32 ++++++++++++++++++++++++++++++-- > 2 files changed, 31 insertions(+), 3 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > index 4039e64cd342..e6aa84f806f7 100644 > --- a/drivers/irqchip/irq-gic-v3-its.c > +++ b/drivers/irqchip/irq-gic-v3-its.c > @@ -1615,7 +1615,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, > } > > /* Convert 52bit PA to 48bit field */ > - baser_phys = GITS_BASER_PHYS_52_to_48(baser_phys); > + baser_phys = GITS_BASER_ADDR64K_FROM_PHYS(baser_phys); > } > > retry_baser: > diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h > index c00c4c33e432..b880b6682fa6 100644 > --- a/include/linux/irqchip/arm-gic-v3.h > +++ b/include/linux/irqchip/arm-gic-v3.h > @@ -320,6 +320,15 @@ > #define GITS_IIDR_REV(r) (((r) >> GITS_IIDR_REV_SHIFT) & 0xf) > #define GITS_IIDR_PRODUCTID_SHIFT 24 > > +#ifdef CONFIG_ARM64_PA_BITS_52 > +#define GITS_PA_HI_MASK (0xfULL) > +#define GITS_PA_SHIFT 52 > +#else > +/* Do not use the bits [51-48] if we don't support 52bit */ > +#define GITS_PA_HI_MASK 0 > +#define GITS_PA_SHIFT 48 > +#endif > + > #define GITS_CBASER_VALID (1ULL << 63) > #define GITS_CBASER_SHAREABILITY_SHIFT (10) > #define GITS_CBASER_INNER_CACHEABILITY_SHIFT (59) > @@ -343,6 +352,7 @@ > #define GITS_CBASER_WaWb GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, WaWb) > #define GITS_CBASER_RaWaWt GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWaWt) > #define GITS_CBASER_RaWaWb GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWaWb) > +#define GITS_CBASER_ADDRESS(x) ((x) & GENMASK_ULL(GITS_PA_SHIFT, 12)) > > #define GITS_BASER_NR_REGS 8 > > @@ -373,8 +383,26 @@ > #define GITS_BASER_ENTRY_SIZE_SHIFT (48) > #define GITS_BASER_ENTRY_SIZE(r) ((((r) >> GITS_BASER_ENTRY_SIZE_SHIFT) & 0x1f) + 1) > #define GITS_BASER_ENTRY_SIZE_MASK GENMASK_ULL(52, 48) > -#define GITS_BASER_PHYS_52_to_48(phys) \ > - (((phys) & GENMASK_ULL(47, 16)) | (((phys) >> 48) & 0xf) << 12) > + > +/* > + * With 64K page size, the physical address can be upto 52bit and > + * uses the following encoding in the GITS_BASER[47:12]: > + * > + * Bits[47:16] of the register => bits[47:16] of the base physical address. > + * Bits[15:12] of the register => bits[51:48] of the base physical address. > + * bits[15:0] of the base physical address are 0. > + * Clear the upper bits if the kernel doesn't support 52bits. > + */ > +#define GITS_BASER_ADDR64K_LO_MASK GENMASK_ULL(47, 16) > +#define GITS_BASER_ADDR64K_HI_SHIFT 12 > +#define GITS_BASER_ADDR64K_HI_MOVE (48 - GITS_BASER_ADDR64K_HI_SHIFT) > +#define GITS_BASER_ADDR64K_HI_MASK (GITS_PA_HI_MASK << GITS_BASER_ADDR64K_HI_SHIFT) > +#define GITS_BASER_ADDR64K_TO_PHYS(x) \ > + (((x) & GITS_BASER_ADDR64K_LO_MASK) | \ > + (((x) & GITS_BASER_ADDR64K_HI_MASK) << GITS_BASER_ADDR64K_HI_MOVE)) > +#define GITS_BASER_ADDR64K_FROM_PHYS(p) \ > + (((p) & GITS_BASER_ADDR64K_LO_MASK) | \ > + (((p) >> GITS_BASER_ADDR64K_HI_MOVE) & GITS_BASER_ADDR64K_HI_MASK)) I don't understand why you need this masking logic embedded in these macros? Isn't it strictly an error if anyone passes a physical address with any of bits [51:48] set to the ITS on a system that doesn't support 52 bit PAs, and just silently masking off those bits could lead to some interesting cases. This is also notably more difficult to read than the existing macro. If anything, I think it would be more useful to have GITS_BASER_TO_PHYS(x) and GITS_PHYS_TO_BASER(x) which takes into account CONFIG_ARM64_64K_PAGES. > #define GITS_BASER_SHAREABILITY_SHIFT (10) > #define GITS_BASER_InnerShareable \ > GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable) > -- > 2.13.6 > Thanks, -Christoffer