Received: by 2002:ab2:68d2:0:b0:1f5:ff5f:8f32 with SMTP id e18csp115501lqp; Thu, 18 Apr 2024 06:59:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWTuMq3AkfdnpiVIFuuLcxTTE2o8EoV8ew0FfwMZnZHu0LdF4fE5R0W8Kdr7CHXAS7fFG1aCgYpqB01GTYm+TFmJ6QAF7H+9QBf7wKhWA== X-Google-Smtp-Source: AGHT+IHL2BIeBtywYyB5QNz0K2Vx+8G0N9yvqViczLqNZAIfOPosi0IoPFsQuybXT4d2cJ+TSDqb X-Received: by 2002:a05:620a:254f:b0:78e:d2ef:3ae0 with SMTP id s15-20020a05620a254f00b0078ed2ef3ae0mr4398826qko.5.1713448771872; Thu, 18 Apr 2024 06:59:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713448771; cv=pass; d=google.com; s=arc-20160816; b=OmV4ITOjQgQK/edGN8OJq7/HfxXjCJf9j1lawSBRbLSk/429mAGK5epDLpSTFAQvR9 KewZc08BIWpquUKFAQznJgC14rP3JGSR8kts6O1e+COlYpf94COKT6kDVenx5qBjpfw+ oyaqAEHGK7gIYnmr/WrWSNs9xeiOIgc0QCF7lc2lJuSZGG5Z/zRdTF8zfR8hR/Hd6C4N aEh/4fDkn/nbJ987oA/i2BjbHuLZXHARY8DdDW6z6zadU/krgJngamMKc7/LUimpUD9N 3WqzkJ80BuLvs97hjD6bwdvgt2ICD2zWLMbMyCS725lgJBumsT1STS3X88seRVQgwXUp cv1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=yNDmhaFib5vUgSCj1EuHEP0N8f9l8mHKtBljI9aZIys=; fh=IMafqdxo8Eu+wrl2XBOHcPondxBEhctZJiZ7gysyrwA=; b=Qy7KokniWxnC48eHDHK+cZbafdBhMSgbRjszIBcZknRH0LejRh5wQ8l7OTW8HRCfIM spiawVLDqHnzw+YHEZ3s3Af44K/btGsD1A9l2nb75NLf7n1xcXdfm97Ymhy78CmB5WUM uW/uI1oUgZE8hi85ghVxgYcSA/qdwAHHMUZCJQMiSnHAAcy0MgCK/cg2WoyIFEbiteVs 3pRUslSrVF/Ji6PdCplw0Sd89Ymld1Fhdg1FPdNo/txuDb/X4n8wqGp0ejhXZCvdz2Kd xh/+HWcJSjksbO1GYmaso3UU4NDXB6zS6xImmtX3YOHArFq0KA/eyCM8Zwo+GYNYYJed 1TwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JKFr0e5d; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150225-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y23-20020a05620a09d700b0078ee852d752si1459128qky.404.2024.04.18.06.59.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 06:59:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JKFr0e5d; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150225-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 681A31C21A1D for ; Thu, 18 Apr 2024 13:59:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB12C165FD3; Thu, 18 Apr 2024 13:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JKFr0e5d" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 86A831649D2 for ; Thu, 18 Apr 2024 13:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713448740; cv=none; b=OTmXlp9Z/ZhZYjvclDOPYrCrteCTtHFU9f8jncG+nhMwFk2alnosk61ge+hVc1RfGKQvCn2hOse1pwHyRQ1eQxEqmKZMaLehoMywC8e6a6rIbbfCyIXX9o5SdOTCeJ+WhqFhBKcf3ydyFXfCpYtlwpW3xihBCKSrWWBKZ2ANj5A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713448740; c=relaxed/simple; bh=jfJM8dSb6kGhQc66FRxX40igRNLtbqPBPjraUYrcYeU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VkxNk+Vpy9Z93XN+4Wk1JJ2URL0553HlUoJYmothqAytD09eNuZTm6zSEPkOZ/j7+oBKOpG3T69UDqjRsq46GQrt3T7KKqv8mqKZLmQuVXfokol7NG8S9eiwjtpzgxKVyybvouQUEdfTKCBhmXcDvaWai5ECSqyT1J0mZ+DtX+E= 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=JKFr0e5d; arc=none smtp.client-ip=209.85.215.202 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 Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5d5a080baf1so928491a12.1 for ; Thu, 18 Apr 2024 06:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713448739; x=1714053539; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yNDmhaFib5vUgSCj1EuHEP0N8f9l8mHKtBljI9aZIys=; b=JKFr0e5d8H4A5jufLLQ28H0ENJ/8+aeFjRpZau5tDyynDdenWvHHYuyz3X6fNchT7y ncuGLkybbx03H20nUu4s/gwr1as/f/60P0yr95NFSMrOyjVY9F4xwxMqVof3BmQYA2dD usEBi3hVPCWpwA5bvGnygRJwgbXJROV4s5+1dSslV/uvMKJavcmK34P9Fjcu8GmA+tQs 63stFCCwYfoVrtLhWlNJIYRBTMng5BM3scp+4SlYLpySUUdzTWzGWjdDADoO8MZU7Puw 6V1Ci9AyoIfLcGSbF3G0Q3xI6TvEV+V/teXfou4QkCzuk1kBk2rQztC9zHmyLhY3Ytk7 Vbow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713448739; x=1714053539; h=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; bh=yNDmhaFib5vUgSCj1EuHEP0N8f9l8mHKtBljI9aZIys=; b=JkDGX90yggQRD4BupugSgc8ZGy0mkT+1RSwM5nVeP/KzMcA6fm/FLtoSkjQef9IAKt cHTocOcWq6ehlFsmi0DmKgHGSubNoatPinvkj9+MSaKDN1vcYfd/ctrkwbWvj+qA5+FV SVFF0G0REFWN6yedux9vEt5no+tkx9co+S4wzpx9/MG3lt3gBGFtdCxIJhdk76BfcYZz FWSmi2HRQmhu12iK5JseUw/H4yOUq6VKJnxXzQ/QfdccUEn53O1/VkHAWAPG2WhDCcpH zmlbUFupl0SenRq5TAnO+UjXxL+jgW+E358bRG4eyRJ9tcyur7vckgtBcmpMlo1lprB6 XmLQ== X-Forwarded-Encrypted: i=1; AJvYcCWOh5F7XxQwW8Gt01QgrcQWwDwtoqXmKfJQwgzslGcmh/e9pF2ZSMeHNXleP4RhDdWYZ9PHFJyVOaVSmIAvM49ICAleYdf6EJ4j660i X-Gm-Message-State: AOJu0YzHtc7i4EbwqiJnCE3Vnd8bJSKjXirAs4uRDPuBk2zVWk8V/A7A GsqE9Df8fEgp/gQQfdG9D00u43mjnhpy6hvmP5go2Z5eHnUB+BgcdsiWi6jtlZoXAPWpNPo9DFE PRQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:4854:0:b0:5d5:1e4d:c845 with SMTP id x20-20020a634854000000b005d51e4dc845mr24856pgk.10.1713448738618; Thu, 18 Apr 2024 06:58:58 -0700 (PDT) Date: Thu, 18 Apr 2024 06:58:56 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240417150354.275353-1-wei.w.wang@intel.com> Message-ID: Subject: Re: [RFC PATCH v1] KVM: x86: Introduce macros to simplify KVM_X86_OPS static calls From: Sean Christopherson To: Wei W Wang Cc: "pbonzini@redhat.com" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="us-ascii" On Thu, Apr 18, 2024, Wei W Wang wrote: > On Thursday, April 18, 2024 12:27 AM, Sean Christopherson wrote: > > On Wed, Apr 17, 2024, Wei Wang wrote: > > > Introduces two new macros, KVM_X86_SC() and KVM_X86_SCC(), to > > > streamline the usage of KVM_X86_OPS static calls. The current > > > implementation of these calls is verbose and can lead to alignment > > > challenges due to the two pairs of parentheses. This makes the code > > > susceptible to exceeding the "80 columns per single line of code" > > > limit as defined in the coding-style document. The two macros are > > > added to improve code readability and maintainability, while adhering to > > the coding style guidelines. > > > > Heh, I've considered something similar on multiple occasionsi. Not because > > the verbosity bothers me, but because I often search for exact "word" matches > > when looking for function usage and the kvm_x86_ prefix trips me up. > > Yeah, that's another compelling reason for the improvement. > > > IIRC, static_call_cond() is essentially dead code, i.e. it's the exact same as > > static_call(). I believe there's details buried in a proposed series to remove > > it[*]. And to not lead things astray, I verified that invoking a NULL kvm_x86_op > > with static_call() does no harm (well, doesn't explode at least). > > > > So if we add wrapper macros, I would be in favor in removing all > > static_call_cond() as a prep patch so that we can have a single macro. > > Sounds good. Maybe KVM_X86_OP_OPTIONAL could now also be removed? No, KVM_X86_OP_OPTIONAL() is what allow KVM to WARN if a mandatory hook isn't defined. Without the OPTIONAL and OPTIONAL_RET variants, KVM would need to assume every hook is optional, and thus couldn't WARN. static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) { memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops)); #define __KVM_X86_OP(func) \ static_call_update(kvm_x86_##func, kvm_x86_ops.func); #define KVM_X86_OP(func) \ WARN_ON(!kvm_x86_ops.func); __KVM_X86_OP(func) #define KVM_X86_OP_OPTIONAL __KVM_X86_OP #define KVM_X86_OP_OPTIONAL_RET0(func) \ static_call_update(kvm_x86_##func, (void *)kvm_x86_ops.func ? : \ (void *)__static_call_return0); #include #undef __KVM_X86_OP kvm_pmu_ops_update(ops->pmu_ops); } > > kvm_ops_update() already WARNs if a mandatory hook isn't defined, so doing > > more checks at runtime wouldn't provide any value. > > > > > As for the name, what about KVM_X86_CALL() instead of KVM_X86_SC()? Two > > extra characters, but should make it much more obvious what's going on for > > readers that aren't familiar with the infrastructure. > > I thought the macro definition is quite intuitive and those encountering it for the > first time could get familiar with it easily from the definition. > Similarly, KVM_X86_CALL() is fine to me, despite the fact that it doesn't explicitly > denote "static" calls. Repeat readers/developers will get used to KVM_X86_SC(), but for someone that has never read KVM code before, KVM_X86_SC() is unintuitive, e.g. basically requires looking at the implementation, especially if the reader isn't familiar with the kernel's static call framework. In other words, there needs to be "CALL" somewhere in the name to convey the basic gist of the code. And IMO, the "static" part is a low level detail that isn't necessary to understand the core functionality of the code, so omitting it to shorten line lengths is a worthwhile tradeoff.