Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4155163pxk; Tue, 22 Sep 2020 11:39:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm5feZn6Q07x8OmbdBd9mhbB6sgchySacCQ1lNU/2pUmiQgETc0kgI1qIBeDENOWLZXnji X-Received: by 2002:a17:906:1157:: with SMTP id i23mr6761368eja.440.1600799969336; Tue, 22 Sep 2020 11:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600799969; cv=none; d=google.com; s=arc-20160816; b=bERaAldNdJlogaylg86iUkc4q8HEUJjWLw2e25Z23W3yEeVTnNbu3fo1hFDYyC0GcK /rhQTmDC2QsJc4HFyAQqLMCtuEWbMAQNHbDyDgQLyzrCW4GaF22NCS8bsN9g/T6piOV4 8ZWZjy5mQ55xumCG+i6cOSphpQNLnHdC3Owt9Qf41goBZsPZoDv/cU0+j3ZxVL+GvO4j vWW4AXAKrKJyudL9eRJgWmprWgogSFd+4vty7ase6L88sk2+vOXqQj4PdI+yIqjxKA6T 9NnJ6p/QzRViq6T0p87YoLnMNvh4U3gZkps08E13JbHYpH5YEJi6jyJoNvApcs9q5RqE nNkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ig3mZwlM5VgOYpaLezhg7vQFxV24lXeVdfnz5xWj0rM=; b=EmMGDLFRgfcueQQX7SpGuo8HlmQy5utjpqD3Zqeas0bh8CcUpIAvBzG1v7XA+TENLJ ueUa4ocPQIilcrkyFw7aBls/NMtCxam4dXgqY99hNs6E9OWTr7I/zDWy31U54Z0Qg0u7 J1i/hDwH2HXLdUgbmYSw4fkSBaaw01GZD9RbioU52KL1zXaDuIMq3STbmr/2PrLndX6G rtDNLMJG5O5MH75teI96UMl2RoYO/LQqny8oMq8tv/lVY2t7ZJyf/+d21ibgSLxcrWsR f+nPmuO6YilT2P0i/djN7bgS5rvLdUoV2e2D2mUGIPdSvrv6RV/fdNKS8TGhL7+Xo10e l/GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j74lrtCw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n18si9137691edt.207.2020.09.22.11.39.04; Tue, 22 Sep 2020 11:39:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j74lrtCw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726732AbgIVSe5 (ORCPT + 99 others); Tue, 22 Sep 2020 14:34:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726614AbgIVSe4 (ORCPT ); Tue, 22 Sep 2020 14:34:56 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D73C061755 for ; Tue, 22 Sep 2020 11:34:56 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id l15so2781639wmh.1 for ; Tue, 22 Sep 2020 11:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ig3mZwlM5VgOYpaLezhg7vQFxV24lXeVdfnz5xWj0rM=; b=j74lrtCwlnu6fqYOp87AYQKgh20vY4HWutnBUDTD/MqKbmkWvoiV1gzSZV1V651W6t 0EKrZbRNvxSaOS5XQN/3rRjYUWD+Ybjv7r9BGve2BX11HJKB1svj+6D+/qfyXmfvs5PX +uTe4FmQnZePv8i6hoTB84tksthKi2ioxGQFqtqwFVhQQsPsEIsaZHKXIpuaML4TRitw C99CuqPCX6sqXqJwRmpmlW0UUiuKt8OkI4se3513BsxjHTyOHyDzrjDiH2IAT20a8hxQ syrZurWX6+zVVt9bSCPXFUuRjAYKQbteOrwVjfILeDBIkZQWQziXt/ZnAD2Waf7SR4a8 vZ0g== 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; bh=Ig3mZwlM5VgOYpaLezhg7vQFxV24lXeVdfnz5xWj0rM=; b=lVK9okyblYMarb2Gc6JLzmzENAPn9Wrs1VawwC2rrGvR3JNyBpLl4M/KGbxAaI5iFx 485vAaAo7665sS4ko5PsLGyKZwdpc7fcWu2Pelm3Rs6F5cjRFe3mkc7rfU8N+Jd48YHc 7fXSk4ZWSNikdQ0I8/dJenIWttLTgZx3snZK9xq1BQ801ufWzrMQ/7d1yDrVYelJmhgu d0/Cx8U3214JIf/hbyqvS6usQu/Cm37KJLTk7pr/b9kGoy54bbPZ4IgEZzivEibTzw7Q jKLc+j6gJScDq7P2VD+iJswJ6vANd3AFG/CR7j4Pno5v1K+jHwyBWcPPHu2xSpHd/pu9 A4Pg== X-Gm-Message-State: AOAM532LsudEGDaytiv6WVZTInTvCqvDRddxBvvE+vgS3XL12xBHymZc HvqS5OBjz8DoPew/8ml6ecXv3A== X-Received: by 2002:a1c:40a:: with SMTP id 10mr1283670wme.61.1600799694728; Tue, 22 Sep 2020 11:34:54 -0700 (PDT) Received: from google.com ([2a01:4b00:8523:2d03:55c2:2cdf:ff31:96a3]) by smtp.gmail.com with ESMTPSA id 63sm29411016wrh.71.2020.09.22.11.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 11:34:53 -0700 (PDT) Date: Tue, 22 Sep 2020 19:34:52 +0100 From: David Brazdil To: Will Deacon Cc: kvmarm@lists.cs.columbia.edu, Catalin Marinas , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Dennis Zhou , Tejun Heo , Christoph Lameter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 10/11] kvm: arm64: Set up hyp percpu data for nVHE Message-ID: <20200922183452.xalwog2ojsc5ogpe@google.com> References: <20200916173439.32265-1-dbrazdil@google.com> <20200916173439.32265-11-dbrazdil@google.com> <20200918122219.GD31096@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200918122219.GD31096@willie-the-truck> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > -#define this_cpu_ptr_nvhe(sym) this_cpu_ptr(&kvm_nvhe_sym(sym)) > > -#define per_cpu_ptr_nvhe(sym, cpu) per_cpu_ptr(&kvm_nvhe_sym(sym), cpu) > > +/* Array of percpu base addresses. Length of the array is nr_cpu_ids. */ > > +extern unsigned long *kvm_arm_hyp_percpu_base; > > + > > +/* > > + * Compute pointer to a symbol defined in nVHE percpu region. > > + * Returns NULL if percpu memory has not been allocated yet. > > + */ > > +#define this_cpu_ptr_nvhe(sym) per_cpu_ptr_nvhe(sym, smp_processor_id()) > > Don't you run into similar problems here with the pcpu accessors when > CONFIG_DEBUG_PREEMPT=y? I'm worried we can end up with an unresolved > reference to debug_smp_processor_id(). Fortunately not. This now doesn't use the generic macros at all. > > /* The VMID used in the VTTBR */ > > static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); > > @@ -1258,6 +1259,15 @@ long kvm_arch_vm_ioctl(struct file *filp, > > } > > } > > > > +#define kvm_hyp_percpu_base(cpu) ((unsigned long)per_cpu_ptr_nvhe(__per_cpu_start, cpu)) > > Having both kvm_arm_hyp_percpu_base and kvm_hyp_percpu_base be so > completely different is a recipe for disaster! Please can you rename > one/both of them to make it clearer what they represent? I am heavily simplifying this code in v4. Got rid of this macro completely, so hopefully there will be no confusion. > > - if (!kvm_pmu_switch_needed(attr)) > > + if (!ctx || !kvm_pmu_switch_needed(attr)) > > return; > > > > if (!attr->exclude_host) > > @@ -49,6 +49,9 @@ void kvm_clr_pmu_events(u32 clr) > > { > > struct kvm_host_data *ctx = this_cpu_ptr_hyp(kvm_host_data); > > > > + if (!ctx) > > + return; > > I guess this should only happen if KVM failed to initialise or something, > right? (e.g. if we were booted at EL1). If so, I'm wondering whether it > would be better to do something like: > > if (!is_hyp_mode_available()) > return; > > WARN_ON_ONCE(!ctx); > > so that any unexpected NULL pointer there screams loudly, rather than causes > the register switch to be silently ignored. What do you think? Unfortunately, this happens on every boot. I don't fully understand how the boot order is determined, so please correct me if this makes no sense, but kvm_clr_pmu_events is called as part of CPUHP_AP_PERF_ARM_STARTING. The first time that happens is before KVM initialized (tested from inserting BUG_ON(!ctx)). That's not a problem, the per-CPU memory is there and it's all zeroes. It becomes a problem with this patch because the per-CPU memory is not there *yet*.