From nobody Wed Sep 14 15:57:46 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MSQ2y27wCz4cRTf; Wed, 14 Sep 2022 15:57:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MSQ2y1gQlz3GPJ; Wed, 14 Sep 2022 15:57:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663171066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HNt9b8c9b7OeYEv80jtz0Z72IpzPhEyi9xSKLSDilk0=; b=qDgSD1GFQy0RyjhlfnK4tx5Lpb7eN/8lh057BUIHO6nOrFuhm7pgMijrNiSfReBubBWgpV K/d1NCCLWnvnitRW15J9xK7Q+FCWPn4mOaMst5AYRJCx6xSq7q7bGKwgCMCKRep1hqHZlq abfb2aRZ1wDge0HayXjCVabwobpA9oxetS7WTkj5lsyfhBTCy/NG2HxqKoYVP79p64IYOM DHLqyiGXKzjRH3f96gsYC7g9x/uxmsB6e+TS1/gZYVdRWdxGNAJNgvrSLN8zlH9H14zCb5 qIP3F8R86Ez69tC1vTG0lDnKN/kiOUdVxJdlXNJRjp26dooMCX41ZD82iPDUxg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MSQ2y0mZXzk19; Wed, 14 Sep 2022 15:57:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28EFvkWk010706; Wed, 14 Sep 2022 15:57:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28EFvkQx010705; Wed, 14 Sep 2022 15:57:46 GMT (envelope-from git) Date: Wed, 14 Sep 2022 15:57:46 GMT Message-Id: <202209141557.28EFvkQx010705@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 2eddd8ebf96a - main - i386: explain the handshake between copyout_fast.s and page fault handler List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2eddd8ebf96a83fdb01d1a7e45e2d652aa05f4b8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663171066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HNt9b8c9b7OeYEv80jtz0Z72IpzPhEyi9xSKLSDilk0=; b=RT/peJRiodyXtHEs2VD+I66OLVDmbzHpDJ0QYL+MJhyQquEMDYjMtpG6gi2uWaW4rN7Ph3 I3+RyauJ8VjdAUnSxiaHUGSzJX+SqgysFGyKcAgur8wC/DHHuPX2zPfFqrBt22eSqUxMrg fg3uZRpqchP9XBr9jeklkHfBlJGqFbJQLGi8KP9NO6+e9uyuDg1PYdJUK+fN4RQC2yDN0L NIUsavKxpBsjwbKJJljxk7dDP2IIeyBdzIwzfpIyoqrflx7JMHG2sYecOb0uq6uFMhej9H LmO9MDnxLQ0K3L2Dydp6p2oNHR0Zj3yHRxe3SHVzTKa+NXk/PLJH7rb7isRMwA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663171066; a=rsa-sha256; cv=none; b=CJzsxns97YS4yFFpD6KU9wc9mQVPtNn1GfWYcLPrbRh8i9aL9yFeT4rcp8ieCEmP5shf9Y GIvKnHydbGPUOQ3vrKY5sfYm5xDk9tJB3twRKYZ1jbYiKjJnYphmJOQ5NATqSKXh7zOj2E ghI1aoBgjyO9fU+z4iISgU9ddS52GtvW5a2ic5MROVMyXlqrZEVY8VLAPlyHCr4m86R7IJ EW5kl7K0qTr6tLVK5o+kwSbJTlOfY6QDVOYRDahW/Wi3mcB+CGIBI97sA/vhJBXtY3M/Gg SSaI0XsPoNdhpprHaoloZrH1dem9yUJ/ncqC4Bvnnv7qV5F/RWEm3IMqhuvrng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2eddd8ebf96a83fdb01d1a7e45e2d652aa05f4b8 commit 2eddd8ebf96a83fdb01d1a7e45e2d652aa05f4b8 Author: Konstantin Belousov AuthorDate: 2022-09-09 20:44:48 +0000 Commit: Konstantin Belousov CommitDate: 2022-09-14 15:47:57 +0000 i386: explain the handshake between copyout_fast.s and page fault handler Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/i386/i386/copyout_fast.s | 11 +++++++++++ sys/i386/i386/exception.s | 33 ++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/sys/i386/i386/copyout_fast.s b/sys/i386/i386/copyout_fast.s index 4391f36b18e4..2aa17a5c45c8 100644 --- a/sys/i386/i386/copyout_fast.s +++ b/sys/i386/i386/copyout_fast.s @@ -37,6 +37,17 @@ #include "assym.inc" +/* + * Fast path for copyout code. We switch to user space %cr3 and perform + * move operation between user memory and copyout buffer, located in the + * trampoline area. We must switch to trampoline stack, because both + * user and kernel buffer accesses might cause page fault. + * + * Page fault handler expects %edx to point to the onfault routine. + * Handler switches to idlePTD and calls the routine. + * The routine must restore the stack, enable interrupts, and + * return to the caller, informing it about failure. + */ .text ENTRY(copyout_fast) diff --git a/sys/i386/i386/exception.s b/sys/i386/i386/exception.s index a2a6f5311a87..1a950b80b9b6 100644 --- a/sys/i386/i386/exception.s +++ b/sys/i386/i386/exception.s @@ -130,15 +130,25 @@ IDTVEC(prot) jmp irettraps IDTVEC(page) testl $PSL_VM, TF_EFLAGS-TF_ERR(%esp) - jnz 6f + jnz upf testb $SEL_RPL_MASK, TF_CS-TF_ERR(%esp) - jnz 6f + jnz upf cmpl $PMAP_TRM_MIN_ADDRESS, TF_EIP-TF_ERR(%esp) - jb 6f + jb upf + + /* + * This is a handshake between copyout_fast.s and page fault + * handler. We check for page fault occuring at the special + * places in the copyout fast path, where page fault can + * legitimately happen while accessing either user space or + * kernel pageable memory, and return control to *%edx. + * We switch to the idleptd page table from a user page table, + * if needed. + */ pushl %eax movl TF_EIP-TF_ERR+4(%esp), %eax addl $1f, %eax - call 7f + call 5f 1: cmpl $pf_x1, %eax je 2f cmpl $pf_x2, %eax @@ -159,23 +169,24 @@ IDTVEC(page) je 4f cmpl $pf_y2, %eax je 4f - jmp 5f + jmp upf_eax 2: movl $tramp_idleptd, %eax subl $3f, %eax - call 8f + call 6f 3: movl (%eax), %eax movl %eax, %cr3 4: popl %eax movl %edx, TF_EIP-TF_ERR(%esp) addl $4, %esp iret -5: popl %eax -6: pushl $T_PAGEFLT - jmp alltraps -7: subl (%esp), %eax +5: subl (%esp), %eax retl -8: addl (%esp), %eax +6: addl (%esp), %eax retl + +upf_eax:popl %eax +upf: pushl $T_PAGEFLT + jmp alltraps IDTVEC(rsvd_pti) IDTVEC(rsvd) pushl $0; TRAP(T_RESERVED)