From patchwork Tue May 4 13:02:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 96751 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o44D3GAx003783 for ; Tue, 4 May 2010 13:03:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759746Ab0EDNCv (ORCPT ); Tue, 4 May 2010 09:02:51 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:62583 "EHLO mail-px0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753330Ab0EDNCt (ORCPT ); Tue, 4 May 2010 09:02:49 -0400 Received: by pxi5 with SMTP id 5so812578pxi.19 for ; Tue, 04 May 2010 06:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type:content-transfer-encoding; bh=Y7K+q8AxAooNLOSmewi1xHl9RrGTxUhO+dK6sPr4tpM=; b=BrL9BfhYoSN/9tT1TMOh0nWUtjeo7GA1Z4s0c3uwHkPfEBdMoVaK0lO0JqLixtFZzE VI/du8Xt9gXOHloyng3hzw2hzwGRCCQ6EEjCYX4DJwQMJgtb0M1t39cK6OcWSZq2bCSd z+WGA/XkBQgnS+p8Sn/FdMMKsoUWgru4eQna8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=GBuQZY038e71dGlwQwnADiV4PzfI9XkWuXKzN+QKRZmeOSE+0AdGY3b6C9Imo82qA3 xqa2NfE4GGzBkXY7nm9SkBN8HOmjnauRQt1DwEFOwmLK5l6CVRugZTcEmjQivAiYVOXa pXPSz4njKRUNLZb3GQjPLtwOzIHN3IFwx7I/U= Received: by 10.142.119.10 with SMTP id r10mr6640184wfc.192.1272978168320; Tue, 04 May 2010 06:02:48 -0700 (PDT) Received: from stein (v079161.dynamic.ppp.asahi-net.or.jp [124.155.79.161]) by mx.google.com with ESMTPS id e16sm705755wfg.2.2010.05.04.06.02.45 (version=SSLv3 cipher=RC4-MD5); Tue, 04 May 2010 06:02:47 -0700 (PDT) Date: Tue, 4 May 2010 22:02:47 +0900 From: Takuya Yoshikawa To: Takuya Yoshikawa Cc: avi@redhat.com, mtosatti@redhat.com, agraf@suse.de, yoshikawa.takuya@oss.ntt.co.jp, fernando@oss.ntt.co.jp, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-ia64@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, benh@kernel.crashing.org, paulus@samba.org, linuxppc-dev@ozlabs.org, arnd@arndb.de, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC][PATCH 5/12] x86: introduce __set_bit() like function for bitmaps in user space Message-Id: <20100504220247.2e97ac01.takuya.yoshikawa@gmail.com> In-Reply-To: <20100504215645.6448af8f.takuya.yoshikawa@gmail.com> References: <20100504215645.6448af8f.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.0; i486-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 04 May 2010 13:03:16 +0000 (UTC) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index abd3e0e..3138e65 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -98,6 +98,45 @@ struct exception_table_entry { extern int fixup_exception(struct pt_regs *regs); +/** + * set_bit_user_non_atomic: - set a bit of a bitmap in user space. + * @nr: Bit offset. + * @addr: Base address of a bitmap in user space. + * + * Context: User context only. This function may sleep. + * + * This macro set a bit of a bitmap in user space. + * + * Restriction: the bitmap pointed to by @addr must be 64-bit aligned: + * the kernel accesses the bitmap by its own word length, so bitmaps + * allocated by 32-bit processes may cause fault. + * + * Returns zero on success, or -EFAULT on error. + */ +#define __set_bit_user_non_atomic_asm(nr, addr, err, errret) \ + asm volatile("1: bts %1,%2\n" \ + "2:\n" \ + ".section .fixup,\"ax\"\n" \ + "3: mov %3,%0\n" \ + " jmp 2b\n" \ + ".previous\n" \ + _ASM_EXTABLE(1b, 3b) \ + : "=r"(err) \ + : "r" (nr), "m" (__m(addr)), "i" (errret), "0" (err)) + +#define set_bit_user_non_atomic(nr, addr) \ +({ \ + int __ret_sbu; \ + \ + might_fault(); \ + if (access_ok(VERIFY_WRITE, addr, nr/8 + 1)) \ + __set_bit_user_non_atomic_asm(nr, addr, __ret_sbu, -EFAULT);\ + else \ + __ret_sbu = -EFAULT; \ + \ + __ret_sbu; \ +}) + /* * These are the main single-value transfer routines. They automatically * use the right size if we just have the right pointer type.