Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp604895ybh; Tue, 21 Jul 2020 03:31:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuFCqozw6DJxzpbQ1bAFev4dVPZCRDsO2iQS9EkZNqqLqfplFNoIh1r8bkaoeuH3u1osnL X-Received: by 2002:a05:6402:b86:: with SMTP id cf6mr24550982edb.42.1595327504472; Tue, 21 Jul 2020 03:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595327504; cv=none; d=google.com; s=arc-20160816; b=u0s5/EZRY6F92lfHac5iVUKPUa9aB6IyG8eq95pVxMwHOo+VCOmFn+FZLqRNJmOzQQ yRQomQXMbut8N3aRJHhupU4M5JYJGaZjEtB98kBTbEUVcb0jJ2annKBg1yJ8vdBKzx9F oSjOL3vJ7WHRG5G3UaA/iI23zEfUlGpDZQYNix5owB7M4DaL0u/gXz+ItVDYK4t67Ekn 9ft+A8dV5KdAp9wBUKy9UbqjzV3oj21zLao9n9vafbDUTFugKH9FNxKixqLOY3b1hW1M C02PD8hl2N2j1TMhZuj0vSNsQwuG2e+OUZquJUvnxubdHpAVjQNcuP0r3kMMZElaJ+R/ 6UKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=zve33nddAY1CvVFMV1CpDpP9i+R8xzZxDJhHrrAhrZg=; b=Dh+eDx2nNtbuX3ly7hT5sVQYLbg8y5QGU5f4R2gvgvb8wLCUJfUMeh4hfDiYEZ39sX qPxO/pSLCMkyc+iakgYwsOGA1Q4wwqzG4eYazVmHJVjI9yH0nsAqYvJExYPQ+QnrVuec Jvz4u6WZ9mwbSDBAwye8rVw1F6f9s7st6I2C69gVRs0aH/JYGiHrtNXeEalE0/CKDjxq KO61HeZxn2mC4QSYifN7UHp8ujB0bJwrW1nGVj93Rc6HF9HK2GLxNTgM0CSoPFMJxvEi 3dj9utZzcPwlttunnDefwsDhDx9IVEf3VIpaI6gmRvYIeJT+RL1S2ROB7evcDLIxSOn+ KzGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=o+Ls339+; 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 y19si13151118eje.247.2020.07.21.03.31.21; Tue, 21 Jul 2020 03:31:44 -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=o+Ls339+; 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 S1728931AbgGUKa4 (ORCPT + 99 others); Tue, 21 Jul 2020 06:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729267AbgGUKap (ORCPT ); Tue, 21 Jul 2020 06:30:45 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BF74C0619D9 for ; Tue, 21 Jul 2020 03:30:45 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id i6so13441906qkn.22 for ; Tue, 21 Jul 2020 03:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zve33nddAY1CvVFMV1CpDpP9i+R8xzZxDJhHrrAhrZg=; b=o+Ls339+l6oe6R/c+fszNAahS+PvwvIihTw2ab2Dgd7Pz+NFkeLhuTOzqA/tK2oKi6 0OQp0hwrc1zrTqic751h0I50NxcUOJCgN+rmkI0NInw3wudTKPe+lVdMguBFgDsRS7hK 4vV9/ZHqy97/AU2xumW9R4Hy2mbSeoD5N1fjdzD4p9NE6Qwt9vPnbIHh6AIRsAp4SQCB TGWstlXI3lncN3vgRQEslBDdhz/Cm12BroSjn1xlH3rQ1e+zaUQKALrmtAcY4KWKYxS+ ciorqVf43lqcQmcUMyyqZ/VHnFN0+2t1HYWAt5sVJCPDXhyt6t1ZpitpsNPep4HAItN1 G3vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zve33nddAY1CvVFMV1CpDpP9i+R8xzZxDJhHrrAhrZg=; b=TWRxJtMmlULjPKig+G8Ldv9OFrEFenLrcsZQk5q+Na293VLlogdEMqGGPj2EnFMbz/ rpU83snlQS4hYTyIg0c/EZcsnu8d+k/kIjN5L6T4GrvyzBwToN8fWOGf4MphRh6DmUiA L7kuS1AdyaoKc72Phn/nebOCIpGJcTleYKRXzVc4i7vV65h3CowEyJjDcLXLLR+vKdd0 ep61Dq/7W61S0kJ33yvvMKsTU8hsZmBMaNg/ndTblFpUuqO/PDKFwZ0QdtcTnp8yoNnF Nmo2Kmy6DPCtvRaMbEtQUsRy0e2H9JrB3SVYP07bMqQ+cfmOdmmowvHwh8lgS2/MeRAq STow== X-Gm-Message-State: AOAM530v6syquewGmJtVkw32RksDCymbsM1bt0XngAkceb/pLiwfwuM6 sQkhDp5zvceddF/FsfCm7Bz4syz4BQ== X-Received: by 2002:ad4:4a6d:: with SMTP id cn13mr26776898qvb.165.1595327444500; Tue, 21 Jul 2020 03:30:44 -0700 (PDT) Date: Tue, 21 Jul 2020 12:30:14 +0200 In-Reply-To: <20200721103016.3287832-1-elver@google.com> Message-Id: <20200721103016.3287832-7-elver@google.com> Mime-Version: 1.0 References: <20200721103016.3287832-1-elver@google.com> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH 6/8] instrumented.h: Introduce read-write instrumentation hooks From: Marco Elver To: elver@google.com, paulmck@kernel.org Cc: will@kernel.org, peterz@infradead.org, arnd@arndb.de, mark.rutland@arm.com, dvyukov@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce read-write instrumentation hooks, to more precisely denote an operation's behaviour. KCSAN is able to distinguish compound instrumentation, and with the new instrumentation we then benefit from improved reporting. More importantly, read-write compound operations should not implicitly be treated as atomic, if they aren't actually atomic. Signed-off-by: Marco Elver --- include/linux/instrumented.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h index 43e6ea591975..42faebbaa202 100644 --- a/include/linux/instrumented.h +++ b/include/linux/instrumented.h @@ -42,6 +42,21 @@ static __always_inline void instrument_write(const volatile void *v, size_t size kcsan_check_write(v, size); } +/** + * instrument_read_write - instrument regular read-write access + * + * Instrument a regular write access. The instrumentation should be inserted + * before the actual write happens. + * + * @ptr address of access + * @size size of access + */ +static __always_inline void instrument_read_write(const volatile void *v, size_t size) +{ + kasan_check_write(v, size); + kcsan_check_read_write(v, size); +} + /** * instrument_atomic_read - instrument atomic read access * @@ -72,6 +87,21 @@ static __always_inline void instrument_atomic_write(const volatile void *v, size kcsan_check_atomic_write(v, size); } +/** + * instrument_atomic_read_write - instrument atomic read-write access + * + * Instrument an atomic read-write access. The instrumentation should be + * inserted before the actual write happens. + * + * @ptr address of access + * @size size of access + */ +static __always_inline void instrument_atomic_read_write(const volatile void *v, size_t size) +{ + kasan_check_write(v, size); + kcsan_check_atomic_read_write(v, size); +} + /** * instrument_copy_to_user - instrument reads of copy_to_user * -- 2.28.0.rc0.105.gf9edc3c819-goog