Skip to contentSkip to conversation

a todo entry

parisc-linux Jurij Smakov 2 participants 2 messages Oct 11, 2001

lore
Share & tools
lore
#0 lore raw

Hi!

Quoted 5 lines · Matthew Wilcox

#define KERNEL_DS 0
#define USER_DS mfsp(3)
#define get_ds() (KERNEL_DS)
#define get_fs() mfsp(2)
#define set_fs(x) mtsp(x, 3)

I've been looking at it for the last two days and I still cannot understand it :-). Why do You want set_fs to write to sr3? If set_fs changes sr3, but we access memory in __get_user and __set_user using sr2, it is not going to work (I think). By now I'm pretty convinced that set_fs should operate on sr2 (which is supported by John's post). IMHO, sr2 should behave like that (just a summary of what was said before):

a) In userspace sr2 is always 0, so that everybody can make their syscals.
b) sr2 is set to sr3 when we enter the kernel.
c) get_fs returns sr2 and set_fs sets sr2, so that we can always use sr2 as the space in __get_user/__set_user
d) When we return to userspace from the kernel, sr2 is set to 0 again.

While modification of uaccess.h to satisfy c) is more or less trivial, real problem for me is b) and d). I'm not quite sure, where to look for these entries and returns? I would guess, entry.S is the right place, but obviously I didn't RTFM enough to hack it yet.

Another thing which confuses me a lot is a way the exception table is constructed in __get_kernel_asm/__get_user_asm:

"\t.section __ex_table,\"a\"\n"        \
"\t.dword\t1b\n"                       \
"\t.dword\t(2b-1b)+3\n"                \

"\t.previous"

What is the function of this "+3" thing? If 2b and 1b are the word-aligned addresses of the instructions (which, I think, they are), this does not make much sense. When the instruction at 1b fails, it will try to skip (2b-1b)+3 bytes, which is 7, if 1b and 2b refer to subsequent instructions. In other places it is just (2b-1b), which is perfectly understandable. It would be great, if someone could explain it.

Best regards,

Jurij.

#1 lore raw
Quoted 9 lines · Jurij Smakov
Quoted 5 lines

#define KERNEL_DS 0
#define USER_DS mfsp(3)
#define get_ds() (KERNEL_DS)
#define get_fs() mfsp(2)
#define set_fs(x) mtsp(x, 3)

I've been looking at it for the last two days and I still cannot understand it :-). Why do You want set_fs to write to sr3?

That was a mistake -- should be #define set_fs(x) mtsp(x, 2)

Quoted 7 lines

a) In userspace sr2 is always 0, so that everybody can make their syscals.
b) sr2 is set to sr3 when we enter the kernel.
c) get_fs returns sr2 and set_fs sets sr2, so that we can always use sr2 as the space in __get_user/__set_user
d) When we return to userspace from the kernel, sr2 is set to 0 again.

Yes.

Quoted 5 lines

While modification of uaccess.h to satisfy c) is more or less trivial, real problem for me is b) and d). I'm not quite sure, where to look for these entries and returns? I would guess, entry.S is the right place, but obviously I didn't RTFM enough to hack it yet.

Right. I suspect the only place(s?) we need to set sr2 to 0 is where we set sr4-7 to the user's space ID, and set sr2 to sr3 in the same places we set sr4-7 to 0. But that theory needs setting up and testing...

Signature · 1 line
Revolutions do not require corporate support.