Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp3976279ima; Tue, 23 Oct 2018 14:38:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV61wgoARyhVdjl7eS2CWwY19Wm6Ft0olemhQogcW18b3EQ5e708OfEZEJ/+E+VwKWMmMGURz X-Received: by 2002:a62:120b:: with SMTP id a11-v6mr51290036pfj.165.1540330707281; Tue, 23 Oct 2018 14:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540330707; cv=none; d=google.com; s=arc-20160816; b=txHlMKcbQktrJM6V9kNOq0IcP0gru27hB0zGYQlEh7XBKrek0PTPXZHAHnQIS1tqWd bSWQ7pPKN9oFpEh5ZNipPKfIVn+Y+JC/ajRd9xXczZmsSc9c5dfXxGEFQktwMJK1/GbW JS21hx1Lf5qA7rEQSqis+RxVrTkM64dTCU+OHbTVDXWaTRNnQCy8Qc3TgRo9suKg9atc hOAjECqCNAw1Rdu6ukkosJuQyVZPznjhkCqHa8Wm8Frujl9wDqisTymc93mW5N/6hRLO PlH/KVOdc5BMHf3x6DrztGcbqbKHjSKgM4rNKJ4nAxH/Wk6nbSv9TCPTripSKmx1kwhd 6MNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=9TeBZENTG4lUlljtOFNGnausIJ9loexqClGDhlY00q0=; b=Bp2NhKosXsj3pcaCesTP/srjP7lMRvpQsNHQqANjTGtGO4yxz7CG4iJ1abzQisSH9j 4CXMqwpw2jmWlb6YSlT0OKpm/zm5+nLWPw4pTpELQYrBDqBgI73FIsGtwKuzQWholo79 GJMqQRIROXCczyP8Q+BKTqrNRNqXC3LG9dK6tpfi93WIjdpG7n2/q4PWxWSgb/mWr5id /FsmnczXLypT2WEDSci+L0LTvr3JkCX2Aa59ouRtEn356HnJprnE9JJ8Q7ZsC4UPpjO/ w85tGcFAUeRkbz8+1SangGoHhEj+AOhCJkw6qyIrakbAhgQRKdGJ64sIYi3FZGCLqOPP zSsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JtoyO3mZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si2199396pls.378.2018.10.23.14.38.12; Tue, 23 Oct 2018 14:38:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JtoyO3mZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729068AbeJXGBT (ORCPT + 99 others); Wed, 24 Oct 2018 02:01:19 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33335 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728575AbeJXGBT (ORCPT ); Wed, 24 Oct 2018 02:01:19 -0400 Received: by mail-lj1-f195.google.com with SMTP id z21-v6so2820304ljz.0; Tue, 23 Oct 2018 14:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to; bh=9TeBZENTG4lUlljtOFNGnausIJ9loexqClGDhlY00q0=; b=JtoyO3mZ13IGzAbCIgy6S5RYsmImtY6hfg34KQRQ2X3TR1VVri5yBZ/LUjBcD0TzXa 0s8L1kB/YwwSuVWbA3820PquvwCu3SkJCcO1geuaAaOGfUNh9JAvXkHX3kScSRePUVzs LpBgTT1JYuKJ1aT49DAJUFExgxQPahyLwVz4BPku8ogRZBoPGO9RswhALPMjDi8XbttO OjGxJeSt7f0J7GWI7q5EdlapOM+CLE2SPmDyplRRclUZ20Yaw/5nyVtaOA6eSk9/RtMb rtjjIO80ygFKzuE+VuAYK60mF+XSs2WkRVh4yBh7Fgr9V0xTBNIf9zkz+/Qr1wr90r6X Paxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to; bh=9TeBZENTG4lUlljtOFNGnausIJ9loexqClGDhlY00q0=; b=FpbpxAwKLEmXDfy/uazfjNkN09RAySspZSohBqTcu4iXtmC2aQtKMhDXc/Ra1GDii2 BHiyx9U6/xtEGzVTYeaRnhcc5BUVHal6lv2MaYdXfk33b37E7oVBSl/N9It92+NVYLIH caQApND1Fz3MkJSTTKqsreI+GsrAD0GxVfEpy/ahbLx+3dYv9a84LrASIV3YKq+3b4XA LwwVVV+3XQ9IFJOPmIWIWr7k+FhlFN1IAZWKf42BsnHYqugbaxBsDqWVU1plQb+sac1/ mNb3ZfwbGcWNhB3dyB299lywXOASss2L9VXk/l4BCuBt1o+CsWlskz8q+dx+u8GdxTM0 sYbg== X-Gm-Message-State: AGRZ1gKoPdcecuDUbP/fzxSXc4eLBkHDFL0bUAkMBrFEd8luG31rfW98 Qb79rW9hJOLfVeEiwA0vcPc= X-Received: by 2002:a2e:84c5:: with SMTP id q5-v6mr5777858ljh.65.1540330564560; Tue, 23 Oct 2018 14:36:04 -0700 (PDT) Received: from localhost.localdomain (91-159-62-169.elisa-laajakaista.fi. [91.159.62.169]) by smtp.gmail.com with ESMTPSA id y127-v6sm377950lfc.13.2018.10.23.14.36.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 14:36:03 -0700 (PDT) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Mimi Zohar , Kees Cook , Matthew Wilcox , Dave Chinner , James Morris , Michal Hocko , kernel-hardening@lists.openwall.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: igor.stoppa@huawei.com, Dave Hansen , Jonathan Corbet , Laura Abbott , Vlastimil Babka , "Kirill A. Shutemov" , Andrew Morton , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/17] prmem: shorthands for write rare on common types Date: Wed, 24 Oct 2018 00:34:52 +0300 Message-Id: <20181023213504.28905-6-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181023213504.28905-1-igor.stoppa@huawei.com> References: <20181023213504.28905-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wrappers around the basic write rare functionality, addressing several common data types found in the kernel, allowing to specify the new values through immediates, like constants and defines. Note: The list is not complete and could be expanded. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Vlastimil Babka CC: "Kirill A. Shutemov" CC: Andrew Morton CC: Pavel Tatashin CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- MAINTAINERS | 1 + include/linux/prmemextra.h | 133 +++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 include/linux/prmemextra.h diff --git a/MAINTAINERS b/MAINTAINERS index e566c5d09faf..df7221eca160 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9459,6 +9459,7 @@ M: Igor Stoppa L: kernel-hardening@lists.openwall.com S: Maintained F: include/linux/prmem.h +F: include/linux/prmemextra.h F: mm/prmem.c MEMORY MANAGEMENT diff --git a/include/linux/prmemextra.h b/include/linux/prmemextra.h new file mode 100644 index 000000000000..36995717720e --- /dev/null +++ b/include/linux/prmemextra.h @@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * prmemextra.h: Shorthands for write rare of basic data types + * + * (C) Copyright 2018 Huawei Technologies Co. Ltd. + * Author: Igor Stoppa + * + */ + +#ifndef _LINUX_PRMEMEXTRA_H +#define _LINUX_PRMEMEXTRA_H + +#include + +/** + * wr_char - alters a char in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_char(const char *dst, const char val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_short - alters a short in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_short(const short *dst, const short val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_ushort - alters an unsigned short in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_ushort(const unsigned short *dst, const unsigned short val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_int - alters an int in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_int(const int *dst, const int val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_uint - alters an unsigned int in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_uint(const unsigned int *dst, const unsigned int val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_long - alters a long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_long(const long *dst, const long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_ulong - alters an unsigned long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_ulong(const unsigned long *dst, const unsigned long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_longlong - alters a long long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_longlong(const long long *dst, const long long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_ulonglong - alters an unsigned long long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_ulonglong(const unsigned long long *dst, + const unsigned long long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +#endif -- 2.17.1