Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp261760lqe; Wed, 10 Apr 2024 00:58:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXm083IESq1/NX80+8bK2qtngK7/K/G0BqxcZy1n6d3Mo3qm0VQY0bso5tfWngCC7we3D8l4MGSh6v3hzaHYOPxBTuAPAYHfEXtxm6h5w== X-Google-Smtp-Source: AGHT+IGlw060gol96ru3jDtJEI3iuo4wbdtNL/xS4W1lb+MhhptXGjK0PTJ8C+bAUbueFvzesdDL X-Received: by 2002:a17:903:2692:b0:1e4:25e8:c2f2 with SMTP id jf18-20020a170903269200b001e425e8c2f2mr1735124plb.41.1712735888346; Wed, 10 Apr 2024 00:58:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712735888; cv=pass; d=google.com; s=arc-20160816; b=otSr0TgvJbt8dKcJYIsPTHjdTv46eAc8vKdQ9CGGB7pK+3NA+ngo44+nTFFEPu3U2M 5rnMUs4v95dVUs3AAK/0E7yVa71RLLnq50ppB8BGOWpIJFiatAYu/K/d+tWn8zvK3Pve +NY7ZXCnkGRqL6DokUHH44dig6t3+V9LF31SxnRl6Nsm0zE5OH3efVhWCW+Z4YOX/bK0 YB7cvOI8PM4WWrioYCBy7qvXLFKMePU8eBYKd/z9mVPe1mFSmz6CG8EHLxy0NLKhkKFB puWJQlcNv8AC6DxDFSlg6UyIoulGKum6XCrzx+AgUt59ZbqbR2/FUQqtJQ7hdKR0Ay82 /M3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=cTYU2WKjEg4LKgoYtKisI8CAnT5DmGk1CAXrBgmuGkk=; fh=V3jTGpVMT+MlRAqwpmHhYYp+lUizD0NvGBdD/N1rfjU=; b=n94vMFC/AXbyi7CZGqbRWfBM78VYkS/pzA6T7S/PoBt2O2teF4AGQIpiVduKD1uMw9 XMxTBlG7XBfrMD94tcIWfoR+cYINjjUUA/lGA5dWrBmgJQtPFFOtBW8hbMx2cA5PVuwF lbLM8/Q+e9s8rLSfz0eT4xBjW2iAEZreUO/jUbAvLuWjLfS+1bGnJVKEb/fmOxG3l8Ut iUj/P55ekSv5vuXfnBm9kLd1icnaarHoH3hPOHQlOdxvKqIeUoglxEjR3Z7Jn3n3m0bC j9pO0M20MgaGKvMyo6IE6MnQqNcdZQdhrpxwB22jqplSyhGGQ/TFbYoZ9zR06p7Kfo2R u6cQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-138120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q18-20020a170902dad200b001dc4b6c737dsi10544880plx.338.2024.04.10.00.58.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 00:58:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-138120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9A71D283C0B for ; Wed, 10 Apr 2024 07:58:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4BA313D508; Wed, 10 Apr 2024 07:57:50 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B029613D2BC for ; Wed, 10 Apr 2024 07:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712735870; cv=none; b=S+4PNKnT8vgD3WbqkFByWnqboS7c2thCDwjjZXpwEwThh+0iH/k8O/bUX+zCWe/2/JlrdcWtLjv5DQYEbaD8JXezZalModSltuDus13hkK8bkpb/1j1gsyJteHinSg4yT9h4yQCm6hvTxwk8srciDOL+0TcyWUMu314J05kD9H0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712735870; c=relaxed/simple; bh=zSqtZOr6T9tpCLOf2qNdLQbDEt4yULfVFFG7OBHKU5Y=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gCg70VFnO3kVWFlxlwktcoQXAl6LYqgoF/kPtk/IfX0GcGHefXBjYnsLIaP/94GJwdfqTFhowCN9L4eWyxsrRKTp4uDWCADyQbJLm3fWlLRWEajSgsUlmnecX42F1tOnmyY7uUf57NxXFsROrCm2oBffpXW3WbmCFWeYE9W9uAk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D915B1480; Wed, 10 Apr 2024 00:58:17 -0700 (PDT) Received: from [10.162.43.6] (a077893.blr.arm.com [10.162.43.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 81A413F766; Wed, 10 Apr 2024 00:57:42 -0700 (PDT) Message-ID: <32ddd2a6-22c6-49d2-aebb-da5a2e99748d@arm.com> Date: Wed, 10 Apr 2024 13:27:39 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/3] arm64: tlb: Improve __TLBI_VADDR_RANGE() Content-Language: en-US To: Gavin Shan , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, maz@kernel.org, oliver.upton@linux.dev, ryan.roberts@arm.com, apopple@nvidia.com, rananta@google.com, mark.rutland@arm.com, v-songbaohua@oppo.com, yangyicong@hisilicon.com, shahuang@redhat.com, yihyu@redhat.com, shan.gavin@gmail.com References: <20240405035852.1532010-1-gshan@redhat.com> <20240405035852.1532010-3-gshan@redhat.com> From: Anshuman Khandual In-Reply-To: <20240405035852.1532010-3-gshan@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/5/24 09:28, Gavin Shan wrote: > The macro returns the operand of TLBI RANGE instruction. A mask needs > to be applied to each individual field upon producing the operand, to > avoid the adjacent fields can interfere with each other when invalid > arguments have been provided. The code looks more tidy at least with > a mask and FIELD_PREP(). > > Suggested-by: Marc Zyngier > Signed-off-by: Gavin Shan This looks much better. Reviewed-by: Anshuman Khandual > --- > arch/arm64/include/asm/tlbflush.h | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) > > diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h > index a75de2665d84..243d71f7bc1f 100644 > --- a/arch/arm64/include/asm/tlbflush.h > +++ b/arch/arm64/include/asm/tlbflush.h > @@ -142,17 +142,24 @@ static inline unsigned long get_trans_granule(void) > * EL1, Inner Shareable". > * > */ > -#define __TLBI_VADDR_RANGE(baddr, asid, scale, num, ttl) \ > - ({ \ > - unsigned long __ta = (baddr); \ > - unsigned long __ttl = (ttl >= 1 && ttl <= 3) ? ttl : 0; \ > - __ta &= GENMASK_ULL(36, 0); \ > - __ta |= __ttl << 37; \ > - __ta |= (unsigned long)(num) << 39; \ > - __ta |= (unsigned long)(scale) << 44; \ > - __ta |= get_trans_granule() << 46; \ > - __ta |= (unsigned long)(asid) << 48; \ > - __ta; \ > +#define TLBIR_ASID_MASK GENMASK_ULL(63, 48) > +#define TLBIR_TG_MASK GENMASK_ULL(47, 46) > +#define TLBIR_SCALE_MASK GENMASK_ULL(45, 44) > +#define TLBIR_NUM_MASK GENMASK_ULL(43, 39) > +#define TLBIR_TTL_MASK GENMASK_ULL(38, 37) > +#define TLBIR_BADDR_MASK GENMASK_ULL(36, 0) > + > +#define __TLBI_VADDR_RANGE(baddr, asid, scale, num, ttl) \ > + ({ \ > + unsigned long __ta = 0; \ > + unsigned long __ttl = (ttl >= 1 && ttl <= 3) ? ttl : 0; \ > + __ta |= FIELD_PREP(TLBIR_BADDR_MASK, baddr); \ > + __ta |= FIELD_PREP(TLBIR_TTL_MASK, __ttl); \ > + __ta |= FIELD_PREP(TLBIR_NUM_MASK, num); \ > + __ta |= FIELD_PREP(TLBIR_SCALE_MASK, scale); \ > + __ta |= FIELD_PREP(TLBIR_TG_MASK, get_trans_granule()); \ > + __ta |= FIELD_PREP(TLBIR_ASID_MASK, asid); \ > + __ta; \ > }) > > /* These macros are used by the TLBI RANGE feature. */