Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1838541lqo; Sun, 19 May 2024 00:44:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7SyiWou1oDqa2LGxT9d6YvlTHwiAvFmVPSvQy98fXRucL4+LS8r8s8KkZiQqJHGVFUUYoNCyLaqw9vLYT+3LkNyRXL6+XDeYlrXrSLQ== X-Google-Smtp-Source: AGHT+IEZmtzLdknz+EKdQcTasLWq19HpVMmv/RemXE+9MIl7KiCtIjKNZe6pqmPci7Jef411ENIx X-Received: by 2002:a17:907:7787:b0:a5a:891b:416b with SMTP id a640c23a62f3a-a5a891b96d7mr915058566b.20.1716104646134; Sun, 19 May 2024 00:44:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716104646; cv=pass; d=google.com; s=arc-20160816; b=arn4rIgXAogkyRgZaXBqXXWUGnTuUaOZazhjm/D1LvUKzIDsymHkHWUw11o6zaUIve 3ZI4nNd3oWrlcvlhvyF3Fxcbn1FHta/BED0q0j+0W/rKA3xrAp0XxCZNuL2JI0bx5F9P yLUwfhqKbc55p5oJLy84HvB14t8hZ8aMLPteU6EbljnqDD4gn6TFnm79MMKhObscnBgk eevI7IZRS8Ej4S23pPeuszFtaZ3ZBhfc5tVam+pX1jlHd4wPcFVogfBETevbA0GVAkLn hZsfT8fEJSdbSiZAJTosPDifP/O38YqkNnSr2bEoqrlNjmYrKMj1F9Ru73oDNa1OsSAb 5W4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=sxw0ppvwN68aKsYdrg7i/nk/Ahqb/+wiMV6TU4JTkq0=; fh=xXqeG/slDmmfenoDuMwkRyi0KQPNCrLC4abnor6D3Wo=; b=grVmJyQ8SIioVASk2ICl9g8Dhw2IA3aVaTBw67z/mcAruxSoQ7exDIgXSkm6luvxot dzI+c6TcgVVYxyIG09EXRtk5UBOf2I5HI+34gh+8ausITIDPWSh+v+nxw+kkcUNF2LVE RO2Fre3uaQ2HG43KEZmPz1nCX4uVGY+Ga76jhMmjdbvZ7xchdX4A9FMx18bpjRqWAJDj YSrgUwL1KjyiO5Rh0I0FXe1Y1Fh6dBDfwxzEW0qUazYLBFBJULv4pHbQtJXlxytn9Ub2 CLf/0us2PApy62N+078EoYzgyeHO6KgYAKZmZ42rRYgC7iQJcdKX5k5Qp/yg8sPBlwPB sDZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Hkzgk/z+"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-183042-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183042-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a894c8b98si581503666b.63.2024.05.19.00.44.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 00:44:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183042-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Hkzgk/z+"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-183042-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183042-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id B06A81F213DD for ; Sun, 19 May 2024 07:44:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54AEF18039; Sun, 19 May 2024 07:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hkzgk/z+" Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 06E2517BA2; Sun, 19 May 2024 07:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716104637; cv=none; b=fQKgs5tW8Qz+1OkAusnqGy8U0qPXeifHp3vEMpma7cw9mvHv+9FA6TMQ+2hXLqdWcEaxzSLOUsCToQ+9SuX/DccDbrd0WlipUxAq/PPr9XVZPn1d+jRkGl56fr1NKY6XqAnU4ZtKP9kuik/wauYl9mhb1FpUOuzEj8jfQRMZPbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716104637; c=relaxed/simple; bh=BLS/3yqG+x+pmzxow4oCh/ZaClvha66n9SalV6XKyPI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=nxgTMr9iF4IRRF+JsHHOHiHGwTCsB+3B8UR9+gVJVcMtZQNc3LughTr2Yxylppr4tfPAZga4z194SsBFx28SMi2Ko+4S8cuyHR/teRt5HoIkWrwyT72JT6it8UZEdpUi6WolC8+HW4rU7PVGzNKAyzY0a+BDZWR+4TAxHu2fdcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hkzgk/z+; arc=none smtp.client-ip=209.85.161.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5b27bbcb5f0so867057eaf.3; Sun, 19 May 2024 00:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716104635; x=1716709435; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sxw0ppvwN68aKsYdrg7i/nk/Ahqb/+wiMV6TU4JTkq0=; b=Hkzgk/z+sjGl3uGZ5/cN8u5niBaqdG6cwZ2yYp4ZHzL2Iz5bU/S3D4jgX9Q/gp59x8 n8c67saLryXiMGxsxNNZV4DJp2V1ORBgQt/fEoyc+h/oe3IRzXIoqaqvPsE2t7YE8+aj SRA5sMpKnmSyuE1fwILppZ/JKQw4NyLqoc0VuhoZTVjKR64FjMOYDO7DX3RYZY8C++jj KqtdXog21jsNEKQUKXTNWiyH+C7ZGDfBObsC69LzlT4U7cd+4Kw+tAhMBTWbkv2zbwqH 2WXy4wOHwOqWyKIVWcrSPEOtNZs8mNvA50vSLIewza6Np0t2fwM6ksdRoSX+GEXqBUa0 858Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716104635; x=1716709435; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sxw0ppvwN68aKsYdrg7i/nk/Ahqb/+wiMV6TU4JTkq0=; b=sUIMdY8mTNquYl7xrMsM4s9lnE0exBIDOILxDnBbMvURyBA1VD9jIXMZlDBj/1c80R fPUOp49Aya32bO9rjUKI4F+0sxuvQgdBZctlA58QONY+/pys110JjojBqq15Fjn+yAud mTSIiHMYYQyaJN8HdCncg72/Nuq1I8chIJu+6OSh9DjTenXyAZ6w/WlZor0Yeg92yTH9 GNiicDhkE/EjlLdI08AxZuoS17EUs7F7eOuwgJvFQCytw5SFLOyFuGQgrzLqh60Edo75 wghJ7Ee+rmzRXykPpNKeivFgVE7eUNDQZMYyrTN9dxhbjaLpoViF9dP9iesJAPBo/CuS lKKA== X-Forwarded-Encrypted: i=1; AJvYcCV8wSN8xOmg5zj1sczS80lHr1fLo9YTI7tljKE/NW708BRPtcuMc2rybJoXeza9A3skDtTgvXT6e5XHdpegg/RTmmiA+wKoO9bNVxbP X-Gm-Message-State: AOJu0Yw/s+4mNtnbW7Mb733vGXimdfMFXPkAyJAXkIKlyGuscdixafs3 nthZqO/qmHOQ2/tvIhD7ph+iTGd4KXiQLNWogTL5/H2gWa+a0csY X-Received: by 2002:a05:6358:8093:b0:192:5510:e3ee with SMTP id e5c5f4694b2df-193bb623eb1mr3124570055d.13.1716104635013; Sun, 19 May 2024 00:43:55 -0700 (PDT) Received: from localhost.localdomain ([120.229.27.58]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b67126b666sm19735722a91.34.2024.05.19.00.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 00:43:54 -0700 (PDT) From: Wardenjohn To: jpoimboe@kernel.org, mbenes@suse.cz, jikos@kernel.org, pmladek@suse.com, joe.lawrence@redhat.com Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Wardenjohn Subject: [PATCH] livepatch: introduce klp_func called interface Date: Sun, 19 May 2024 15:43:43 +0800 Message-Id: <20240519074343.5833-1-zhangwarden@gmail.com> X-Mailer: git-send-email 2.37.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash. This commit introduce a read only interface of livepatch sysfs interface. If a livepatch function is called, this sysfs interface "called" of the patched function will set to be 1. /sys/kernel/livepatch////called This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called. Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface. --- include/linux/livepatch.h | 2 ++ kernel/livepatch/core.c | 18 ++++++++++++++++++ kernel/livepatch/patch.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index 51a258c24ff5..026431825593 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -37,6 +37,7 @@ * @nop: temporary patch to use the original code again; dyn. allocated * @patched: the func has been added to the klp_ops list * @transition: the func is currently being applied or reverted + * @called: the func is called * * The patched and transition variables define the func's patching state. When * patching, a func is always in one of the following states: @@ -75,6 +76,7 @@ struct klp_func { bool nop; bool patched; bool transition; + bool called; }; struct klp_object; diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 52426665eecc..bc055b56dbe5 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -470,6 +470,22 @@ static struct attribute *klp_object_attrs[] = { }; ATTRIBUTE_GROUPS(klp_object); +static ssize_t called_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct klp_func *func; + + func = container_of(kobj, struct klp_func, kobj); + return sysfs_emit(buf, "%d\n", func->called); +} + +static struct kobj_attribute called_kobj_attr = __ATTR_RO(called); +static struct attribute *klp_func_attrs[] = { + &called_kobj_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(klp_func); + static void klp_free_object_dynamic(struct klp_object *obj) { kfree(obj->name); @@ -631,6 +647,7 @@ static void klp_kobj_release_func(struct kobject *kobj) static const struct kobj_type klp_ktype_func = { .release = klp_kobj_release_func, .sysfs_ops = &kobj_sysfs_ops, + .default_groups = klp_func_groups, }; static void __klp_free_funcs(struct klp_object *obj, bool nops_only) @@ -903,6 +920,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj) static void klp_init_func_early(struct klp_object *obj, struct klp_func *func) { + func->called = 0; kobject_init(&func->kobj, &klp_ktype_func); list_add_tail(&func->node, &obj->func_list); } diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c index 90408500e5a3..75b9603a183f 100644 --- a/kernel/livepatch/patch.c +++ b/kernel/livepatch/patch.c @@ -118,6 +118,8 @@ static void notrace klp_ftrace_handler(unsigned long ip, if (func->nop) goto unlock; + if (!func->called) + func->called = true; ftrace_regs_set_instruction_pointer(fregs, (unsigned long)func->new_func); unlock: -- 2.37.3