From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99BED538D8C for ; Thu, 10 Sep 2026 16:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789057459; cv=none; b=Co3jc/rjH/tsV9tmNboyekosCd8PdAR81vUkW9Jt+84I3V6j4rApbDk/lOm/7i4fwPAnNFzeV+yRHnB4N3rh1sJKsItP3dj0a5QjGmaoQe99P+Nq7McWd3huLHTLRcZ5gwkr7bfr/WEm3uk7rylnmNXzVIhsJlj5RyTi9+BPJE4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789057459; c=relaxed/simple; bh=oZlJXyr/vznH7W8+YLWx04wb1lKdYU17YCzYXBRfBHU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JjFoSK8eMA3bwDYJ1gHp9G06bxkK8MZZm8QdbxnzNoMG4JJN9ZUkixGjHs5wRnsdqcXlvhjtBcrIp9TMctp7QAqfeD5gaWcr0TLAV1drCl5Jgzs+p+Uiwf1KiC/ewNIQAETJ4TFV/XfYWgoFTyP0HonsF7Hb/MknkKI29n2aoYk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oLP9mMX3; arc=none smtp.client-ip=209.85.216.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oLP9mMX3" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-38f97b3f853so7953916a91.3 for ; Thu, 10 Sep 2026 09:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789057456; x=1789662256; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0rpxpcs9OXB4KnER7qZ3x6F/Alg7K5WCZ24dhH70660=; b=oLP9mMX3OHITNlhfzK5J1s9E7iJPtoBvlQkhotYZ+n30Q6ryjxW3WL3nkY0NBJL0K9 MB7KB24uu65k1h8sFA3SLm/tDdShVFAy+RRNj3M+UVtBkSti7EFBsxD8AsyroHXSBo8z H8wqCFbga7rwygBVPR7qS7rFCAc0kh+lg8WPFHN1yEHglcGVfmqVETjVA0TAvxDs4hAY jz5IEeTmfb0E9A8Eonb90TBB8gbZHG9fzlzG9eKJKtixKveOXHHpDmnBvO4YcwKvrhl9 ds6RjLks/cadoHhA+03IfoJy59fBnuK5BxN7tZ/Y+MLkHtLCG9oHtmkExxz/6zBGcq66 3Bvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789057456; x=1789662256; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0rpxpcs9OXB4KnER7qZ3x6F/Alg7K5WCZ24dhH70660=; b=GkuVnTqvHmg94skFRlr39gNwgB+Xh0wbJ6aCLxaJIzGxHZJyspn56ukfAZy6u0Geti paEja/BlXAsGFnewq81egoaBkbIgRPGVUsr25160XSRCtflZ1l7BbYpfCXAxol3Luyn7 Dg2Y1vOYtmzafYQe3QzwspoAJUXWLI3JQlWh9VL28db+1KEP+7YxDDEaYTrwWIJ0jgya +Q6L2UMHL0asvKH7Ak95H2LXHRbsW2JfkYRnKl0r4IU7sBQHgfAaI3azzxrxulYNec9H H3zzN1Da/0uimGjQHxjS9I0uofRvXJYVo+WxlQ1vMNj6HSGw0bIE9FQt4SuzecBDHTA/ /OuA== X-Forwarded-Encrypted: i=1; AKwUvBzPDTHyDi8/c9Ary0CqI2fa/y4qxX3vn0EcXYHczOiwzo9mmh3xDoVmhTGFE1u9Gcfp1MrMCHU0GTc=@lists.linux.dev X-Gm-Message-State: AFuF++n91f/srVPQenQZIokzWGSOMu/SJNDvHxIQPOKH6uVKguQ7pdvr i2EsCS0q8G2mH8WSUvZD6JWFYNN7jzgLk5+q6lnieGH4yF+qGtzukfgXHGsNcGTSTLcSlyZSFA8 Wvxe6zw== X-Received: from pjye16.prod.google.com ([2002:a17:90a:ee10:b0:39b:9a0e:78cd]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d644:b0:398:9c00:29ec with SMTP id 98e67ed59e1d1-39b26245cfcmr66792937a91.20.1789057455320; Thu, 10 Sep 2026 09:24:15 -0700 (PDT) Date: Thu, 10 Sep 2026 09:24:14 -0700 In-Reply-To: <5x0d1hj1.ritesh.list@gmail.com> Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902164123.2546762-1-seanjc@google.com> <20260902164123.2546762-13-seanjc@google.com> <5x0d1hj1.ritesh.list@gmail.com> Message-ID: Subject: Re: [PATCH v2 12/20] KVM: selftests: Add APIs to override memory region types with custom memslots From: Sean Christopherson To: Ritesh Harjani Cc: Marc Zyngier , Oliver Upton , Paolo Bonzini , Tianrui Zhao , Bibo Mao , Huacai Chen , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Atish Patra , Alexandre Ghiti , David Hildenbrand , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Itaru Kitayama , Nicholas Piggin Content-Type: text/plain; charset="us-ascii" On Thu, Sep 10, 2026, Ritesh Harjani wrote: > Sean Christopherson writes: > > > Add and use APIs to override memory region types instead of open coding the > > logic in tests, partly to dedup test code, but mostly to add some amount of > > protection against conflicting overrides. This will allow converting more > > tests to override memory regions without taking on too much risk of bugs in > > the long term, e.g. due to silently overriding a region multiple times. > > > > Deliberately "unroll" the loops in __vm_create() and the CMMA test's > > create_main_memslot() to avoid filling all memslots in anticipation of > > adding an "extra" memslot that is for test use and *only* test use, i.e. > > shouldn't be configured by core library code. > > > > Converting tests to overriding memory regions will allow taking the region > > type instead of the raw memslot in the physical page allocator APIs. > > > > May I suggest few changes in the naming of these APIs: > > static inline void vm_override_mem_region(struct kvm_vm *vm, > enum kvm_mem_region_type type, > u32 slot) > { > TEST_ASSERT(vm->memslots[type] == KVM_INVALID_MEMSLOT, > "Memory region type '%u' was already overridden with slot=%u", > type, vm->memslots[type]); > > vm->memslots[type] = slot; > } > > static inline void vm_override_add_mem_region_flags(struct kvm_vm *vm, > enum kvm_mem_region_type type, > enum vm_mem_backing_src_type src_type, > gpa_t gpa, u32 slot, u64 npages, > u32 flags) > { > vm_override_mem_region(vm, type, slot); > vm_userspace_mem_region_add(vm, src_type, gpa, slot, npages, flags); > } > > static inline void vm_override_add_mem_region(struct kvm_vm *vm, > enum kvm_mem_region_type type, > enum vm_mem_backing_src_type src_type, > gpa_t gpa, u32 slot, u64 npages) > { > vm_override_add_mem_region_flags(vm, type, src_type, gpa, slot, npages, 0); > } > > Those "_add_" and "_flags" in the function names easily gives away > the difference in the APIs, rather than differentiating via "__". I am strongly against postfixes like "_flags". We do use postfixes for the VM creation APIs, e.g. vm_create_barebones(), vm_create_with_vcpus(), etc., but only because there are so many possible combinations that differentiating through underscores is completely infeasible (unless we forced callers to regurgitate huge amounts of boilerplace and/or had an absurd number of params), and because the collection of APIs is tree-like, as opposed to a single linear chain of APIs. For this, there is a much more finite set of possibilities, and the set of APIs is a direct liner chain (no underscores => __ => ____). I agree that not capturing that {,__}vm_override_mem_region() adds a userspace memory region isn't ideal, but due to the term "memory region" already being somewhat overloaded, I don't want to have "add" in the name as I think that will make it harder to differentiate between the "enum kvm_mem_region_type" APIs and the "userspace memory region" APIs. And IMO it's totally fine for a function name to express what the API does at a higher level, without capturing the exact operations in explicit detail. E.g. __vm_create() (and even ____vm_create()) obviously does a lot more than literally KVM_VM_CREATE.