Received: by 10.223.176.5 with SMTP id f5csp1920676wra; Thu, 8 Feb 2018 05:46:55 -0800 (PST) X-Google-Smtp-Source: AH8x2275aJkT+7UNRuWIaQsNYdtu+UAIqgFDO/yq36yJxf+pybWt6+YG2lOFNDbg6j12nnUj97N2 X-Received: by 2002:a17:902:678b:: with SMTP id g11-v6mr713227plk.13.1518097615627; Thu, 08 Feb 2018 05:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518097615; cv=none; d=google.com; s=arc-20160816; b=mjWhE9enuf2zEEbQ2Tf9a7P4cCeLVHctnuK45r8lMwgycFx99SM7MN50N5SIgwxVIY M+U35v5qBmqW4lgz7OiC6uFtxyG9TZ2vWCJzexcirkZGXbdlbzEB6M1qBZHf5H4AaB9P lDIHCgONPB43/KYZ4UE2FTLGi5T7QFkXzeMvFMDuV5vOzlb8cK5lGQhPgV+SvDk1nkob yVqD619G4xOKkMOA+ferF8uAn5sgPOCuOKXfX7dzskWdzyCrzyibYF/h7EJU9j/TwU23 qPDIe7X8B1A8Uj/efqPplvKj+D/k9I1J0fSog4KjHj4bHVa4UEyfn4TtwX8Z5M39juOA y5mA== 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=54IHDWhR/sgxnKQsweZHA04zD1THpKHsywz6OLplCiI=; b=ObnBQX5s7lZ4lYuRITrEJmBJcXMfRmYLK/nVfFy54hmH1M8K44tWlQh3c3BTbPtW4T 7LdmviXJgZ1oa3KPJSLIa6OnW+vZtfurxrk3uZn6/+o4RZCETSDEFcaZWu6l/Xys8EWu nRfUwCKEZY7Zhz7culc1Nnn4++5Vp0q25iau7q133hkY7e6cb0rS4Yl+D6nGaTd+LvHz ZVm3t8yELXVE3yMUuWABxDXpbR3v3AQDIy/y7C47uGUCq3FBXKXlpjZhmOTKR2QSxfN9 REqCCFdrZczUeFNVA2dlqx9nvlJnyErKWI0/qck9/buCVLZakBsfDjjSxV9Zw+//E3Pc xGpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PQbc50Oo; 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 l1-v6si8718plg.56.2018.02.08.05.46.41; Thu, 08 Feb 2018 05:46:55 -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=PQbc50Oo; 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 S1752059AbeBHNqC (ORCPT + 99 others); Thu, 8 Feb 2018 08:46:02 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33227 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750961AbeBHNqA (ORCPT ); Thu, 8 Feb 2018 08:46:00 -0500 Received: by mail-wm0-f66.google.com with SMTP id x4-v6so27365435wmc.0 for ; Thu, 08 Feb 2018 05:45:59 -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=54IHDWhR/sgxnKQsweZHA04zD1THpKHsywz6OLplCiI=; b=PQbc50Oo9jduepMThkG782WCRYjKx5LqlCIfXoubGHHChwNYSKx9IcmG+sEjDbn4ob lbkK6E7KXSt8yiy7BfFORFE3MybBoyfVXGMcroxoyPk7AJAyg2+QFhBp5MzS7FGzpSAK QHCMTZQXUSlu5tLA5zwXlKkeVL1MxCFl5DG/0= 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=54IHDWhR/sgxnKQsweZHA04zD1THpKHsywz6OLplCiI=; b=bERmI+7bVpDWKfJkKBErbHlWgs3RT1ny0HyMCImEiYER5xQCnjqzq8dX05MzKGO6/b ToYZPsUVhBcyIFOgC7YnwN87yFZ6tPxzBiEsDl5LYtjBsx8GSdMqEjuqYavAH/zNkYYb lIJSEITtR+vsgWQJvAciHoIM1giaL959MvhWQbDtDjRM7lpQ9KhB4/RbcH9nZco2oqAl puLUrM/UjZEtnhTKO4017AYMOwbL9m/H8GeHQq6VdOWI6xWWYT50YXLyT4BwyK67RGeC 1gCGWO1jv+/hc4qIoxJnMiQ3uHMp4qPsLr/4GQDjQqGxHoW5cm7S7/R3T61353Trru8d YDsg== X-Gm-Message-State: APf1xPALrKJjE4g2YHmisiPZIRuH5Iy19NV3ayNZuKaIe4qr1lNOZGN8 7SDvUCfTQcr1g0jaMm17S017DA== X-Received: by 10.80.135.69 with SMTP id 5mr1565884edv.226.1518097559117; Thu, 08 Feb 2018 05:45:59 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id i32sm2776432eda.89.2018.02.08.05.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 05:45:58 -0800 (PST) Date: Thu, 8 Feb 2018 14:45:57 +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: <20180208134557.GQ29286@cbox> References: <20180109190414.4017-1-suzuki.poulose@arm.com> <20180109190414.4017-3-suzuki.poulose@arm.com> <20180207151023.GD29286@cbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Thu, Feb 08, 2018 at 11:20:02AM +0000, Suzuki K Poulose wrote: > On 07/02/18 15:10, Christoffer Dall wrote: > >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 > >>--- > > > >>+ > >>+/* > >>+ * 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. > > What do you think is the best way to handle such cases ? May be I could add > some checks where we get those addresses and handle it before we use this > macro ? > I don't think the conversion macros should try to hide programming errors. I think we should limit the functionality in the macros to be simple bit masking and shifting. Any validation and masking depending on 52 PA support in the kernel should be done in the context of the functionality, just like the ITS driver already does. > > > >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. > > I thought the 64K_PAGES is not kernel page size, but the page-size configured > by the "requester" for ITS. So, it doesn't really mean CONFIG_ARM64_64K_PAGES. You're right, I skimmed this logic too quickly. > But the other way around, we can't handle 52bit address unless CONFIG_ARM64_64K_PAGES > is selected. Also, if the guest uses a 4K page size and uses a 48 bit address, > we could potentially mask Bits[15:12] to 0, which is not nice. > > So I still think we need to have a special macro for handling addresses with 64K > page size in ITS. > I think it's easier to have the current GITS_BASER_PHYS_52_to_48 and have a corresponding GITS_BASER_PHYS_48_to_52, following Robin's observation. Any additional logic can be written directly in the C code to check consitency etc. Thanks, -Christoffer