Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 865E9C05027 for ; Mon, 23 Jan 2023 11:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230107AbjAWLL7 (ORCPT ); Mon, 23 Jan 2023 06:11:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbjAWLL5 (ORCPT ); Mon, 23 Jan 2023 06:11:57 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8CFE22A0C for ; Mon, 23 Jan 2023 03:11:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3A3BB60E94 for ; Mon, 23 Jan 2023 11:11:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 914BCC433D2; Mon, 23 Jan 2023 11:11:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674472315; bh=fvBZjE+C2lc+hZ1/sSez62FN4+Fmyocapbo76WLNgbI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MqQKfkdoh0Lq8t0o6WkO6AQI7srbvKy94ADF8ln5AkvAxtLFSzxTViCBC3/E01X8g 32QrIK+jOxu5AjulniJzXV0yld8ZZ3SVYudba6eWiMwFcH54ZhdfIpB9UkicExA3SZ ZuymGuFxbxfORUQYwQIotM7dVjZjQ2sA83O95fh7Y5LvInNLmTLuFiQu61Q7ISGu7Z 5Y9upxuX+Q6sKx0jQPCrY8vEjjSBk0+8P2WNnEHQhUXl83ygojcs1oCnkXWECgHyoo 5B45dJetWDkwtieT1HsYCqlo6Wc5VozVHAzSOw4/e2vBEU+MWpZHrq1TDB53t64w5J PMVHnq0Sgii0g== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pJujx-003vDl-6w; Mon, 23 Jan 2023 11:11:53 +0000 Date: Mon, 23 Jan 2023 11:11:52 +0000 Message-ID: <86edrlmrnr.wl-maz@kernel.org> From: Marc Zyngier To: Akihiko Odaki Cc: Oliver Upton , Akihiko Odaki , Mark Brown , linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Mathieu Poirier , Suzuki K Poulose , Alexandru Elisei , James Morse , Will Deacon , Catalin Marinas , asahi@lists.linux.dev, Alyssa Rosenzweig , Sven Peter , Hector Martin Subject: Re: [PATCH v7 7/7] KVM: arm64: Normalize cache configuration In-Reply-To: <0ac18497-8392-8ea3-05ee-7f2377a4374c@gmail.com> References: <20230112023852.42012-1-akihiko.odaki@daynix.com> <20230112023852.42012-8-akihiko.odaki@daynix.com> <86k01gm6ys.wl-maz@kernel.org> <0ac18497-8392-8ea3-05ee-7f2377a4374c@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: akihiko.odaki@gmail.com, oliver.upton@linux.dev, akihiko.odaki@daynix.com, broonie@kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, mathieu.poirier@linaro.org, suzuki.poulose@arm.com, alexandru.elisei@arm.com, james.morse@arm.com, will@kernel.org, catalin.marinas@arm.com, asahi@lists.linux.dev, alyssa@rosenzweig.io, sven@svenpeter.dev, marcan@marcan.st X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 22 Jan 2023 17:36:39 +0000, Akihiko Odaki wrote: > > On 2023/01/22 3:15, Oliver Upton wrote: > > Hey Marc, > > > > On Sat, Jan 21, 2023 at 12:02:03PM +0000, Marc Zyngier wrote: > >> On Thu, 19 Jan 2023 19:46:16 +0000, Oliver Upton wrote: > >>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > >>> index 459e6d358dab..b6228f7d1d8d 100644 > >>> --- a/arch/arm64/kvm/sys_regs.c > >>> +++ b/arch/arm64/kvm/sys_regs.c > >>> @@ -148,17 +148,19 @@ static u32 get_ccsidr(struct kvm_vcpu *vcpu, u32 csselr) > >>> static int set_ccsidr(struct kvm_vcpu *vcpu, u32 csselr, u32 > >>> val) > >>> { > >>> - u8 line_size = FIELD_GET(CCSIDR_EL1_LineSize, val); > >>> + u8 line_size = SYS_FIELD_GET(CCSIDR_EL1, LineSize, val); > >>> + u32 cur = get_ccsidr(vcpu, csselr); > >>> + u8 min_line_size = SYS_FIELD_GET(CCSIDR_EL1, LineSize, cur); > >>> u32 *ccsidr = vcpu->arch.ccsidr; > >>> u32 i; > >>> - if ((val & CCSIDR_EL1_RES0) || line_size < > >>> get_min_cache_line_size(csselr)) > >>> + if (cur == val) > >>> + return 0; > >>> + > >>> + if ((val & CCSIDR_EL1_RES0) || line_size < min_line_size) > >>> return -EINVAL; > >> > >> This doesn't look right. You're comparing the value userspace is > >> trying to set for a given level with the value that is already set for > >> that level, and forbid the cache line size to be smaller. It works if > >> no value has been set yet (you fallback to something derived from > >> CTR_EL0), but this fails if userspace does multiple writes. > > > > Good catch, I tried to skip over the unit/field conversions by doing this > > but it has the consequence of not working as expected for multiple writes. > > > >> The original check is against CTR_EL0, which makes absolute sense > >> because we want to check across the whole hierarchy. It is just that > >> the original code has two bugs: > >> > >> - It fails to convert the CCSIDR_EL1.LineSize value to a number of > >> words (the missing +4). Admire how the architecture is actively > >> designed to be hostile to SW by providing two different formats for > >> the cache line size, none of which is in... bytes. > >> > >> - It passes the full CSSELR value to get_min_cache_line_size(), while > >> this function wants a bool... Yes, there are times where you'd want > >> a stronger type system (did anyone say Rust? ;-) > > > > Hey now, if you say it enough times people are going to start getting > > ideas ;-P > > > >> I propose that we fold something like the patch below in instead > >> (tested with get-reg-list). > > > > Agreed, I've backed out my diff and applied yours. Pushed (with force!) > > to my repo now, PTAL. > > > > -- > > Thanks, > > Oliver > > > > I was so careless that I missed two bugs and failed to test the last > version of my patch. It is fortunate that the bugs were caught by > careful review though we don't have a strong type system (yet). Your > tree looks good to me. Don't beat yourself up! You've done a great job for a first arm64 contribution, and we caught the problem during the review process, which is what it is for. Thanks, M. -- Without deviation from the norm, progress is not possible.