From nobody Tue Jun 16 15:58:19 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 CC69240B6FB for ; Thu, 30 Apr 2026 14:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777558548; cv=none; b=U2Eq0m6oTF8HWFxWFnJ/FiLEe0sLdWozKGWHy6MKodoCmpQsBQi6b6eKyrzY590kNenXWB+r7iV7/YsxXopfmfsVzv3I1Hp5zCPPLQ93VtxePyx4n69QDomStgBlojxzuDmYKZ0my09U5BXv0BUArK2w3o4TQfHfeSg1IzMA1zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777558548; c=relaxed/simple; bh=NUgw9VtHhOH1SDxH2pZXbRmyq38I9DnKn/coZE2Y2ro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=GN+jIO70XYTZ58hJQrZ1wYHOwxUCno2pEaxwZdHNxOC+9umx15U7n1frBe1xcbklS/Bv+rvqtJXaqsLiHLFXT82gR3RlaVAXjUPynU/OIbU4VVG4lHxEJt9S3twPwLeY1k8LWdbV/loXSrS8LZskfrznNx1Hq9IMQTQyAnmKlek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F0y2IHH1; arc=none smtp.client-ip=209.85.128.41 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F0y2IHH1" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4891ad5c074so113175e9.0 for ; Thu, 30 Apr 2026 07:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777558541; x=1778163341; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=Vi8NDKusFCMVruLpinmrdqk1EXLTyT/eTQZyAXfJaw0=; b=F0y2IHH1/8mNd+6AXEKvWhxp8R2WdiSyu+paRogKzMLLbqOdLWVGXgbzApHXxmgfgN l2DBmwm7j7J5K50yzVDKFyfXWmrtfXLKzFlbLmOpp35eW8zn93818dCNBK09Q9whAZ8C tRVOEBvtrnBbW0MUboOcdx4e1/nI+JjZbxXqLfhSfEyT+ycUcyGvbyoRvCaRh0w0I68p eSoSNpxKFxFhWbjo8EdW4LhBsgi7whfgr3xwb1eK36QzNNLEyJRs2oSG5U3vaRmADBsE YQVGg7ijnIK63xlUekX3GthQeSfu+rFNDHABIdm/20hZNKRGVeSHbP53vUxLlw5vvROd lP6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777558541; x=1778163341; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Vi8NDKusFCMVruLpinmrdqk1EXLTyT/eTQZyAXfJaw0=; b=nR8YxxwWvbyx7n+6vDA6GSIfUcgZCbWy0PP5uEu8TiauOI0lDH29T6ra+i1Isi8Idg 5jcnjeqwpRAZUMMeIHeffDhbxsR1I3Zej9uwKQ53mjkJTGOcCHpBTeeV4SyNCjKbu7xI z8PyN7xiDhe8zl8so73QjpriQ7oQ9B+97D27KmJvaWHGd1xIk/bMzgq9zfDjkHynihaC 8uZuO8zpyznIO70G8ZU4OsFIeDVPY0/ztujAt/uB1xWcwrZci/BTLsOzS4cTKKhqHgim CnhRN4vJmwysTZQLbvRhJIR705UvAYBcaXINZ8HIVlChuxszEMe0Y52rm6hrb4O4oLmn o+Fg== X-Forwarded-Encrypted: i=1; AFNElJ8vlb/Ivz4oJ14gnwStfi17k7S7Mu/2OKWAzBrpFwrDRvt1cW75Pkjhu1XGasjXpnTV8Z1Vs+smDyE58d0=@vger.kernel.org X-Gm-Message-State: AOJu0YxwQtnhXtsdoZvsSJpVfa8cFPOuMnP8XHnYL7Cf+EwyXgxSzJej N30UlwKJ4EgiqAc5wJv3oxmg5Pk4TTYbyc7D5moB178/bkIboETuxMkA6BpAztS53Q== X-Gm-Gg: AeBDieskYIc+lxGCe//Ff15col4k2NX+3ldrFFY09QUn3hq64NEW+tRRBNmkY1sbSZa CROnQd7y6dftcwP+In7aAuJxNECN0kjJ2cQFO0u/g1oJmtVpKlvM1H2Eg6+nCbNi9PBMJmI6Y0/ ddNZ+eN0DtHLEd4LsTWBYm6kud/Q3K9+/nSf3R27B0Dt16HrEJa6AsOVAeXeZgBwGF14OcC1Nmc cfE3StWpoMXo7zimbvQkN8Myzs8kH1o7zdz861Q8BlZGE42Wo6Zf4eWafpy0LJCF8IoFjRzau1t FxAwhjur0vbEz0wpgKKT3QOAfTSo9Q4ym2AgSCgzyudQ81UAmjRE7yyteJBSlhMJVu54tId6ZpB JoZhscZHPEkQSOz+WvMTVBb0OvBdrVq91y+f5fRbuil9TZg6qra2ntC17A6TCdMzysYmLTDL+dZ 2AFpcM8WQg5C0gNzVKt1QTewU9q7V84Ef94z8hGTmhLiAX7QS0LaaJheaY7Uixxf1esQVVVoXH7 Tki3udQpw== X-Received: by 2002:a05:600c:8a17:10b0:48a:6321:87f7 with SMTP id 5b1f17b1804b1-48a83089695mr956005e9.8.1777558540959; Thu, 30 Apr 2026 07:15:40 -0700 (PDT) Received: from localhost ([2a00:79e0:288a:8:353:619f:ca87:2581]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a7b9313c9sm44276955e9.11.2026.04.30.07.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 07:15:39 -0700 (PDT) From: Jann Horn Date: Thu, 30 Apr 2026 16:15:33 +0200 Subject: [PATCH] kcov: refactor common handle ID into kcov_common_handle_id Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com> X-B4-Tracking: v=1; b=H4sIAAVk82kC/x3MTQqEMAxA4atI1gZq/Ru9irjQGjWMNtKKDIh3n +Dywce7IVJgitAmNwS6OLJ4jSxNwK2DXwh50gZrbGWK3ODXyYWB5sGdEtDJvotHldNGaMus/hR NOVoaQQ+HOv69965/nj/4b+jTbQAAAA== X-Change-ID: 20260430-kcov-refactor-common-handle-25178495b2eb To: Dmitry Vyukov , Andrey Konovalov , kasan-dev@googlegroups.com, Andrew Morton Cc: Alexander Potapenko , Valentina Manea , Shuah Khan , Shuah Khan , Hongren Zheng , linux-usb@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jann Horn X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1777558537; l=7319; i=jannh@google.com; s=20240730; h=from:subject:message-id; bh=NUgw9VtHhOH1SDxH2pZXbRmyq38I9DnKn/coZE2Y2ro=; b=w1wS50tB8THjaYvysUQGGWgnG9EF+LO73Pv68csEK5kfA8uYeJKksc86HaweNr0lcBbvU9z+c 08zCfmGaVt/BP/BZ2F0vI+j8BtWW7AcZMbnkIlArjRuP127cTiY62qM X-Developer-Key: i=jannh@google.com; a=ed25519; pk=AljNtGOzXeF6khBXDJVVvwSEkVDGnnZZYqfWhP1V+C8= Store common handle IDs in "struct kcov_common_handle_id", which consumes no space in non-KCOV builds. This cleanup removes #ifdef boilerplate code from subsystems that integrate with KCOV (in particular in usbip_common.h and skbuff.h, see the diffstat). This should also make it easier to add KCOV remote coverage to more subsystems in the future. Signed-off-by: Jann Horn Acked-by: Greg Kroah-Hartman Acked-by: Jakub Kicinski Reviewed-by: Dmitry Vyukov --- drivers/usb/usbip/usbip_common.h | 29 +---------------------------- drivers/usb/usbip/vhci_rx.c | 4 ++-- drivers/usb/usbip/vhci_sysfs.c | 2 +- drivers/vhost/vhost.h | 2 +- include/linux/kcov.h | 12 ++++++------ include/linux/skbuff.h | 14 +++----------- include/linux/types.h | 6 ++++++ kernel/kcov.c | 6 +++--- 8 files changed, 23 insertions(+), 52 deletions(-) diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_com= mon.h index 282efca64a01..be4c5e65a7f8 100644 --- a/drivers/usb/usbip/usbip_common.h +++ b/drivers/usb/usbip/usbip_common.h @@ -282,9 +282,7 @@ struct usbip_device { void (*unusable)(struct usbip_device *); } eh_ops; =20 -#ifdef CONFIG_KCOV - u64 kcov_handle; -#endif + struct kcov_common_handle_id kcov_handle; }; =20 #define kthread_get_run(threadfn, data, namefmt, ...) \ @@ -339,29 +337,4 @@ static inline int interface_to_devnum(struct usb_inter= face *interface) return udev->devnum; } =20 -#ifdef CONFIG_KCOV - -static inline void usbip_kcov_handle_init(struct usbip_device *ud) -{ - ud->kcov_handle =3D kcov_common_handle(); -} - -static inline void usbip_kcov_remote_start(struct usbip_device *ud) -{ - kcov_remote_start_common(ud->kcov_handle); -} - -static inline void usbip_kcov_remote_stop(void) -{ - kcov_remote_stop(); -} - -#else /* CONFIG_KCOV */ - -static inline void usbip_kcov_handle_init(struct usbip_device *ud) { } -static inline void usbip_kcov_remote_start(struct usbip_device *ud) { } -static inline void usbip_kcov_remote_stop(void) { } - -#endif /* CONFIG_KCOV */ - #endif /* __USBIP_COMMON_H */ diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c index a75f4a898a41..a678e7c89837 100644 --- a/drivers/usb/usbip/vhci_rx.c +++ b/drivers/usb/usbip/vhci_rx.c @@ -261,9 +261,9 @@ int vhci_rx_loop(void *data) if (usbip_event_happened(ud)) break; =20 - usbip_kcov_remote_start(ud); + kcov_remote_start_common(ud->kcov_handle); vhci_rx_pdu(ud); - usbip_kcov_remote_stop(); + kcov_remote_stop(); } =20 return 0; diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c index 5bc8c47788d4..b98d14c43d13 100644 --- a/drivers/usb/usbip/vhci_sysfs.c +++ b/drivers/usb/usbip/vhci_sysfs.c @@ -425,7 +425,7 @@ static ssize_t attach_store(struct device *dev, struct = device_attribute *attr, vdev->ud.tcp_rx =3D tcp_rx; vdev->ud.tcp_tx =3D tcp_tx; vdev->ud.status =3D VDEV_ST_NOTASSIGNED; - usbip_kcov_handle_init(&vdev->ud); + vdev->ud.kcov_handle =3D kcov_common_handle(); =20 spin_unlock(&vdev->ud.lock); spin_unlock_irqrestore(&vhci->lock, flags); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 4fe99765c5c7..0192ade6e749 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -44,7 +44,7 @@ struct vhost_worker { /* Used to serialize device wide flushing with worker swapping. */ struct mutex mutex; struct llist_head work_list; - u64 kcov_handle; + struct kcov_common_handle_id kcov_handle; u32 id; int attachment_cnt; bool killed; diff --git a/include/linux/kcov.h b/include/linux/kcov.h index 0143358874b0..cdb72b3859d8 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -43,11 +43,11 @@ do { \ /* See Documentation/dev-tools/kcov.rst for usage details. */ void kcov_remote_start(u64 handle); void kcov_remote_stop(void); -u64 kcov_common_handle(void); +struct kcov_common_handle_id kcov_common_handle(void); =20 -static inline void kcov_remote_start_common(u64 id) +static inline void kcov_remote_start_common(struct kcov_common_handle_id i= d) { - kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id)); + kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id.val)); } =20 static inline void kcov_remote_start_usb(u64 id) @@ -99,11 +99,11 @@ static inline void kcov_prepare_switch(struct task_stru= ct *t) {} static inline void kcov_finish_switch(struct task_struct *t) {} static inline void kcov_remote_start(u64 handle) {} static inline void kcov_remote_stop(void) {} -static inline u64 kcov_common_handle(void) +static inline struct kcov_common_handle_id kcov_common_handle(void) { - return 0; + return (struct kcov_common_handle_id){}; } -static inline void kcov_remote_start_common(u64 id) {} +static inline void kcov_remote_start_common(struct kcov_common_handle_id i= d) {} static inline void kcov_remote_start_usb(u64 id) {} static inline void kcov_remote_start_usb_softirq(u64 id) {} static inline void kcov_remote_stop_softirq(void) {} diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 2bcf78a4de7b..a3fe418f7ced 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1082,9 +1082,7 @@ struct sk_buff { __u16 network_header; __u16 mac_header; =20 -#ifdef CONFIG_KCOV - u64 kcov_handle; -#endif + struct kcov_common_handle_id kcov_handle; =20 ); /* end headers group */ =20 @@ -5437,20 +5435,14 @@ static inline void skb_reset_csum_not_inet(struct s= k_buff *skb) } =20 static inline void skb_set_kcov_handle(struct sk_buff *skb, - const u64 kcov_handle) + struct kcov_common_handle_id kcov_handle) { -#ifdef CONFIG_KCOV skb->kcov_handle =3D kcov_handle; -#endif } =20 -static inline u64 skb_get_kcov_handle(struct sk_buff *skb) +static inline struct kcov_common_handle_id skb_get_kcov_handle(struct sk_b= uff *skb) { -#ifdef CONFIG_KCOV return skb->kcov_handle; -#else - return 0; -#endif } =20 static inline void skb_mark_for_recycle(struct sk_buff *skb) diff --git a/include/linux/types.h b/include/linux/types.h index 608050dbca6a..93166b0b0617 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -224,6 +224,12 @@ struct ustat { char f_fpack[6]; }; =20 +struct kcov_common_handle_id { +#ifdef CONFIG_KCOV + u64 val; +#endif +}; + /** * struct callback_head - callback structure for use with RCU and task_work * @next: next update requests in a list diff --git a/kernel/kcov.c b/kernel/kcov.c index 0b369e88c7c9..a43e33a28adb 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -1083,11 +1083,11 @@ void kcov_remote_stop(void) EXPORT_SYMBOL(kcov_remote_stop); =20 /* See the comment before kcov_remote_start() for usage details. */ -u64 kcov_common_handle(void) +struct kcov_common_handle_id kcov_common_handle(void) { if (!in_task()) - return 0; - return current->kcov_handle; + return (struct kcov_common_handle_id){ .val =3D 0 }; + return (struct kcov_common_handle_id){ .val =3D current->kcov_handle }; } EXPORT_SYMBOL(kcov_common_handle); =20 --- base-commit: 57b8e2d666a31fa201432d58f5fe3469a0dd83ba change-id: 20260430-kcov-refactor-common-handle-25178495b2eb -- =20 Jann Horn